Python for absolute beginners – Part4


variable = {"key": "value"}

person = {“name”: “John”, “age”: 23, “city”: “Montreal”}

  • print(person[“age”])  ==> 23
  • print(person.get(“age”)) ==> 23
  • person[“country”] = “canada” print(person) ==> {‘name’: ‘john’, ‘age’: 23, ‘city’: ‘montreal’, ‘country’: ‘canada’}
  • print(person.get(“key”, “Key not found!”) ==> Key not found!


def function_name( "param" ):

def print_some_text(message):
the_text = message
print(f”The message is: {the_text}”)
print_some_text(“a message for you”)

def getFullName(name, lastName):
return name+’ ‘+lastName
print( getFullName(lastName=”Smith”, name=”John”) )


Class Point:
def __init__(self, name, age): = name
self.age = age

def draw(self)
print (f”Hi {}”)

point = Point(“John”, 6)
print ( ==> John
print (point.draw()) ==> Hi John

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s