Win python Cheat Sheet

A Programming › Python cheat sheet in English by win_muids
2,724 views 1,239 downloads 12 Feb 2016 History
3.7 avg · 0 ratings

Function

str()
make the number or symbol
input()
to get infomation from the user
print()
to show some infomation that in the code
int()
the integers
len()
length of the string
#
comment

Addition

string­­+s­tring
Combine together
string­­+n­umber
CRASH!
Number­­+n­umber
Additi­­on­(­Math)

Multip­­li­c­ation and Exponent

string­­*n­umber
Combine the string
string­­*s­tring
CRASH!
number­­*n­umber
Multip­­ly­(­math)
string­­**­s­tring
CRASH!
number­­**­n­umber
Expone­­nt­(­math)
string­­**­n­umber
CRASH!

Convert to binary

user_ number = ' '
 
while user_n­umber != ' 0 ' :
user_n­umber = input ("Enter a number to convert to binary­")
number = int(us­er_­number)
binary­_string = ' '
 
while (number > 0):
remainder = number%2
binary­_string = str(re­mai­nde­r)+­bin­ary­_string
number = number/ /2
 
print ("Binary string is". binary­_st­ring)

Random

import random

intlist = [1,2,3,4,5,]
random_int = random.choice(intlist)
print (intlist, random_int)


fplist = [1.5,2.5,3.5,4.5,5.5]
random_fp = random.choice(fplist)
print (fplist, random_fp)


strlist = ['1', '2', '3', '4', '5']
random_str = random.choice(strlist)
print (strlist, random_str)


mylist = [1, 2, 3, 4, 5, 1.5, 2.5, 3.5, 4.5, 5.5,'1', '2', '3', '4', '5' ]
random_item = random.choice(mylist)
print (mylist, random_item)


myvar1 = 1
myvar2 = 2
myvar3 = 3
varlist =[myvar1, myvar2, myvar3]
random_var = random.choice(varlist)
print (varlist, random_var)

Vocab

Variable
The unknow that can be change
String
a list of character
Float
Decimal number
Integer
Whole number
Syntax
structure of langauge
Boolean
True/False
Length
the length of the string
Modulo
Finds the remainder

Symbol

==
equal to
!=
not equal to
<
less than
>
more than
<=
less than or equal to
>=
more than or equal to
%
Modulo, find remainder
+
plus
-
subtract
*
multiply
**
exponent

Reverse code

while True:
word = input(­"­Please enter a word")
index = 0
reverse = ' '
 
while int(index) < len(word):
reverse = word[i­ndex] + (reverse)
index = int(index) + 1
 
print ("Re­ver­se:­" , reverse)

Name Convention

Rule for giving name
- letter
- numbers
- unders­­core_

Valid name
- _mystr
- my3
- Hello_­­there

Invalid name
- 3my="hi­­" -- cannot start with number
- first name="h­­i"
- first-name
- first+name

Badges

Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.