You are on page 1of 9

firststeps

February 10, 2024

1 Python Essentials
1.1 Session N°1
27/01/2024
hello students
[1]: print("Hello All")

Hello All

[2]: print("Hello All, \nLet's learn python")

Hello All,
Let's learn python

[3]: print("Hello "+"World")

Hello World

[4]: var = "Hello All, \nLet's learn python"


print(var)
var

Hello All,
Let's learn python

[4]: "Hello All, \nLet's learn python"

[10]: x = 10
print(x)
x

10

[10]: 10

[8]: x = 10.5
print(x)

1
x

10.5

[8]: 10.5

[19]: x=1
print(type(x))
type(x)

<class 'int'>

[19]: int

[21]: x=11.65
print(type(x))
type(x)

<class 'float'>

[21]: float

[25]: x="s"
print(type(x))
type(x)

<class 'str'>

[25]: str

[27]: x="same"
print(type(x))
type(x)

<class 'str'>

[27]: str

[29]: x="1"
print(type(x))
type(x)

<class 'str'>

[29]: str

[32]: x=True
print(type(x))

2
type(x)

<class 'bool'>

[32]: bool

[34]: x=False
print(type(x))
type(x)

<class 'bool'>

[34]: bool

[37]: answer = input("What's your name")


print(answer)
answer

What's your name youssef


youssef

[37]: 'youssef'

[14]: age = int(input("What's your Age"))


print(age)
age

What's your Age 24


24

[14]: 24

[41]: salary = float(input("What's your Salary"))


print(salary)
salary

What's your Salary 1250.544454


1250.544454

[41]: 1250.544454

[21]: str(2.5)

[21]: '2.5'

3
[63]: # This is a print function
print("hello") # This is a print function
print("hello1")
# This is a print function print("hello2")
# This is a print function
# print("hello3")
#This is a print functionThis is a print functionThis is a print functionThis␣
↪is a print functionThis is a print functionThis is

# a print functionThis is a print functionThis is a print functionThis is a␣


↪print functionThis is a print functionThis is a print functionThis is a␣

↪print functionThis is a print fu

"""print
lsolfqf
qsfqdf
gsdqgdaq
qghfshgq"""
print("hello1")

hello
hello1
hello1

[64]: # legal variables names


var="a"
my_var="a"
MyVar="a"
myvar1="a"

[65]: # Illegal variables names


2myvar="a"
my-var="a"
my var ="a"

Input In [65]
2myvar="a"
^
SyntaxError: invalid syntax

[31]: "hello Oualid"

[31]: 'hello Oualid'

[33]: 1.2

[33]: 1.2

4
1.2 Session N°2
03/02/2024

[23]: True

[23]: True

[25]: False

[25]: False

[26]: 1 < 2

[26]: True

[28]: 1 > 2

[28]: False

[34]: 1 <= 2

[34]: True

[37]: 1 >= 2

[37]: False

[39]: 1 == 2

[39]: False

[41]: 2 == 2

[41]: True

[43]: 1 != 2

[43]: True

[49]: 1 != 1

[49]: False

[50]: "hello" == "Hello"

[50]: False

5
[51]: "hello" == "hello"

[51]: True

[57]: x = 10
if x > 10: # Si
print("X > 10")
elif x==5: # Sinon Si
print("X == 5")
else: # Sinon
print("X < 10")

X < 10

[64]: age = 25
if age < 18:
print("Mineur")
else:
if age < 65:
print("Adulte")
else:
print("Senior Citizen")

Adulte

[66]: age = 25
if age < 18:
print("Mineur")
elif age < 65:
print("Adulte")
else:
print("Senior Citizen")

Adulte

[68]: True and False

[68]: False

[70]: True and True

[70]: True

[72]: False and False

[72]: False

6
[74]: age =25
age < 5

[74]: False

[76]: age =25


age == 25

[76]: True

[80]: (age == 25) and (age <5)

[80]: False

[82]: True or True

[82]: True

[83]: True or False

[83]: True

[84]: False or True

[84]: True

[86]: False or False

[86]: False

[88]: a = True
b= False
if a and b:
print("Both a and b are true")
else:
print("at least a or b are true")

at least a or b are true

[90]: not True

[90]: False

[92]: not False

[92]: True

7
[93]: x = 10
y = 3

[95]: x+y

[95]: 13

[96]: x-y

[96]: 7

[98]: x/y

[98]: 3.3333333333333335

[100]: x//y

[100]: 3

[101]: x*y

[101]: 30

[102]: x**y

[102]: 1000

[105]: 10%2

[105]: 0

[109]: result =4/2


result

[109]: 2.0

[111]: result/=2
result

[111]: 0.5

[112]: result+=1
result

[112]: 1.5

[118]: result+=5 # result = result +5

8
[120]: result/=2 # result = result/2
result*=4 # result = result * 4

[122]: print(1)
print(2)
print(3)
print(4)

1
2
3
4

[126]: for i in range(6):


print("Hello")

Hello
Hello
Hello
Hello
Hello
Hello

[130]: count = 1
while count <=5:
print(count)
count+=1

1
2
3
4
5

[ ]:

You might also like