This repository has been archived by the owner on Dec 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Extreme simplified notes for python
WZYDominic edited this page Sep 4, 2021
·
13 revisions
To get Table of Contents, expand Pages
then expand Editing Extreme simplified notes for python
x=3 #define x as an integer and assign 3 to x(value of x can be changed later)
setname = ['item1', 'item2', 'item3'] #define 'setname' as a set
print('hello')
hello
count = 1
print(count)
type(count)//gives the type of the variable (e.g int,
1
<class 'int'>
import random
x = random.randint(5, 10)
print(x)
8 //gives a number between 5 and 10 inclusive
def print_test()://defining a function
print('test')
print_test()
print(' ')//create a space(refer to [1])
def print2_test():
print_test()//initiating a function within another function
print_test()
print2_test()
test
[1]
test
test
def test_print(x):
print(x)
y=input('anything')
test_print(y)
anythingwzyd123
wzyd123
import math //retrieve math
x = int(input("number"))
if x > 0:
print('x is positive')
elif x == 0:
print('x is zero')
else:
print('x is negative')
number1
x is positive
x = input("number")
try:
y = float(x)
z = (y-1)+1
print(z)
except:
print('enter a number')
numberz
enter a number
Ttmp = input("key in temperature:")
print("temperature: ", temp)
key in temperature: 74
temperature: 74
n=5
while n>0:
print(n)
n = n-1
print('Blastoff!')
5
4
3
2
1
Blastoff!
while True://infinite loop
line = input('> ')
if line[0] == '#'://line[0] is the first character of the string
continue
if line == 'done'://if input is 'done', infinite loop stops
break
print(line)
print('Done!')
name = ['friend1', 'friend2', 'friend3']//define name as set and assign friend(1-3) in the set
for friend in name://for loops continue until all items in set have been "used"
print('Hello', friend)
print('Done!')
Hello friend1
Hello friend2
Hello friend3
Done!
count = 0
for itervar in [3, 41, 12, 9, 74, 15]:
count = count + 1
print('Count: ', count)
Count: 6