Jul 9, 2024
print("Hello, World!")
print("End of code")
def my_function():
print("Hello, World!")
name = "John"
age = 30
id()
to check the memory location of a variable.a = "name"
print(id(a))
b = "name"
print(id(b)) # Same as id(a) because they contain the same object.
number = 2
print(type(number)) # <class 'int'>
variable = 2.5
print(type(variable)) # <class 'float'>
name = "John"
print(type(name)) # <class 'str'>
variable = None
print(type(variable)) # <class 'NoneType'>
[]
.names = ["Ala", "Max", "Felix"]
print(names[0]) # Ala
print(names[-1]) # Felix
print(names[0:2]) # ['Ala', 'Max']
{}
.student = {
"name": "John",
"email": "john@example.com",
"age": 21
}
print(student["name"]) # John
students = {
"names": ["John", "Jane"],
"ages": [21, 22]
}
{}
.my_set = {1, 2, 2, 3}
print(my_set) # {1, 2, 3}
//
print(10 // 3) # 3
%
print(10 % 3) # 1
**
print(2 ** 3) # 8
if condition:
# execute this code
elif another_condition:
# execute this code
else:
# execute this code
for i in range(5):
print(i)
i = 0
while i < 10:
print(i)
i += 1
break
to exit the loop.continue
to skip the current iteration and continue with the next one.for i in range(10):
if i == 5:
break
print(i)