Professional Documents
Culture Documents
Quazii
Quazii
🔠 Variables
Basic method to assign values to a variable 👇🏻
name = 'Rafeh Qazi'
age = 25
>>> print(name)
>>> print(age)
Rafeh Qazi
25
>>> print(width)
>>> print (height)
400
500
📥 Taking Inputs
You have to assign the value of your input directly to a variable.
Hi Rafeh
🐍 Data Types
Untitled 1
🪢 Strings
Strings can be etither words or sentences (and even numbers somtimes)
name = 'Rafeh'
country = 'USA'
city = 'Los Angeles'
💯 Numbers
There are two number data types 👇🏻
🧱 Integers
age = 28
weight = 146
🏖️ Float
temperature = 65.3
longBeachToLAX = 20.7
💡 Booleans
Indicates whether somethin is true or false.
isMyNameQazi = true
doIHaveAPlaystation = false
📝 Lists
Similar to array in JavaScript, but Python uses the word 'Lists'.
➕ Addition
Adding two or more numbers.
print(5 + 5)
>>> 10
num1 = 6
num2 = 7
print(num1 + num2)
>>> 13
➖ Subtraction
Subtracting two or more numbers.
print(6 - 2)
>>> 4
num1 = 8
num2 = 3
print(num1 - num2)
>>> 5
✖️ Multiplication
Multiplying two or more numbers.
print(6 * 2)
>>> 12
num1 = 8
num2 = 3
print(num1 * num2)
>>> 24
➗ Division
Untitled 3
Dividing two or more numbers.
print(6 / 2)
>>> 3
num1 = 24
num2 = 6
print(num1 / num2)
>>> 4
🌫 Floor Division
Rounds the result down to the nearest whole number
print(5 // 2)
>>> 3
📈 Exponentiation
Multiplies the first number with an exponent equal to the second number.
print(6 ** 2)
# similar to 6*6
>>> 36
num1 = 2
num2 = 6
print(num1 ** num2)
# similar to 2*2*2*2*2*2
>>> 64
🍪 Modulus
Gives the remainder from the division.
print(5/2)
>>> 1
Untitled 4
print(14/3)
>>> 2
🤔 Comparison Operators
Comparison Operators are used to compare variables, etc. within your application.
qaziAge = 28
davidAge = 23
print(qaziAge == davidAge)
>>> False
internetSpeedInLA = 100
internetSpeedinDubai = 100
print(internetSpeedInLA == internetSpeedinDubai)
>>> True
longBeachWeather = 66
sanFranciscoWeather = 57
Untitled 5
print(davidAge > qaziAge)
>>> False
longBeachWeather = 66
sanFranciscoWeather = 57
print(4 <= 5)
>>> True
print(6 <= 5)
>>> False
print(7 >= 6)
>>> True
print(5 >= 6)
>>> False
📚 Dictionaries
def introducer():
person = {
'name': 'Qazi',
'shirt': 'Black',
'laptop': 'Apple',
'phone_number': '224-123-3456',
'assets': 100,
Untitled 6
}
person['shirt'] = 'Orange'
👋
person['assets'] = 1000
print(f" Hi my name is {person['name']},
👕 👨💻
💰 🥝
\\n I am wearing a {person['shirt']} shirt, \\n and the laptop I use to code is an
{person['laptop']}, \\n and my net worth is ${person['netWorth']()} USD, \\n My favorit
e fruits are {person['favoriteFruits']}")
>>> introducer()
`👋 Hi my name is Qazi,
👕 I am wearing a Orange shirt,
👨💻 and the laptop I use to code is an Apple,
💰and my net worth is $950 USD,
🥝My favorite fruits are ['🍎', '🍌', '🍊']`
>>> weather_to_emoji('rain')
'☔'
🍬 For Loops
Example #1: Double Numbers in a List
Untitled 7
Example #2: Find the Max in a List
def find_max(numbers):
current_max = numbers[0]
for number in numbers:
if number > current_max:
current_max = number
return current_max
def word_frequency(phrase):
result = {}
words = phrase.split()
for word in words:
if word not in result:
result[word] = 1
else:
result[word] += 1
return result
Untitled 8
🏗️ Functions
1️⃣ Basic Function without any arguement.
def say_my_name():
print('Rafeh Qazi')
print('John')
print('Kara')
print('Sam')
say_my_name()
>>> Rafeh Qazi
>>> John
>>> Kara
>>> Sam
say_my_name('Rafeh')
>>> Rafeh
# Positional arguments 👇🏻
# greeting('Qazi', 'hello')
# Named arguments 👇🏻
# greeting(greet='Hi', name='Qazi')
Untitled 9
Untitled 10