Skip to main content

Python Introduction

Links

  1. Foundations of Python: Made with ML

Important Basics

variables

# Intenegers
a = 0
# Strings
b = 'Hello world!'
# float
c = 10.05
# boolean
d = True

Lists

list = [0,1,2,3,4,5,6,7,8,9]
list[0]
list[-1]
list[-4:]
len(list)
#Specific elements can be replaced by this way
list[1] = 15
#adding elements
list.append(11)
## Letters
new_list = ['hello','world','hi']
## remove element in a list
new_list[2] = []
list[0:3] = []
# clear the whole list
list[:] = []

Functions

def say_hello():
# block belonging to the function
print('hello world')
# End of function

say_hello() # call the function