Show Menu
Cheatography

Python Reference Cheat Sheet (DRAFT) by

python

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Common Syntaxes

Print a string
print ("hello world) 
hi
Make a comment
#this is a comment
Print new Line
\n
Convert other data type to string
str(ar­gument)
Creating a new variable
name_o­f_v­ariable = function
 

Operation with List (array)

Descri­ption
Syntax (Code)
Print Console
Creating a list
daily_temp = [80,90,54]
Remember, Index starts with 0
Print out a particular index
print(­dai­ly_­tem­p[2])
54
Reassi­gning a new value to particular index
daily_­temp[2] = 100
[80,90­,100]
Printing each index using a
for
loop
for i in range 3:

 
print(­dai­ly_temp [i])
80
90
100
To get the length of the list
and assign to a variable
x = len(da­ily­_temp)
x : 3
To print a list without a definitive length
for i in range(len(daily_high_temps)): 
print(daily_high_temps[i])
80
90
100
Second easier way to loop and print through a list
for i in daily_­temps: 
  print(i):
80
90
100