Python Pioneers: A Beginner's Guide ๐Ÿ‡ช๐Ÿ‡น
8.82K subscribers
346 photos
40 videos
24 files
64 links
Welcome to Python Pioneers: Empowering Ethiopian students to embark on their coding journey.

๐Ÿ“ข Channel: @python_pioneers
๐Ÿ‘ฅ Group: @python_pioneers_chat
Download Telegram
VARIABLES IN PYTHON

แ‰ แ‰€แŒฃแ‹ญ แ‰ Python แˆตแˆˆ variables แˆแŠ•แАแ‰ต แŠฅแŠ•แˆ›แˆซแˆˆแŠ•แข

Stay Tuned!

@python_pioneers
@python_pioneers
๐Ÿ‘3
VARIABLES IN PYTHON

In Python, Variables data values store แˆˆแˆ›แˆจแŒ แАแ‹ แ‹จแˆšแ‹ซแŒˆแˆˆแˆ‰แ‰ตแข แ‰ Mathematics แŠซแ‹จแŠ• a variable is a symbol that represents a numberแก แŠ แ‰ฅแ‹›แŠ›แ‹แŠ• แŒŠแ‹œ แ‹ฐแŒแˆž แŠแ‹ฐแˆ แАแ‹แข แ‰ แ‰ฐแˆ˜แˆณแˆณแ‹ญแก variable แ‰ python แˆˆแˆ†แА data value แˆ˜แŒ แˆชแ‹ซ แАแ‹แก it can be a single letter or a word.

1. Variable Declaration: You declare variables in Python simply by assigning a value to them using the = sign. Variable declare แˆตแŠ“แˆจแŒ แ‰ computerแŠก memory แ‹แˆตแŒฅ แ‹จแˆแŠ•แˆแˆแŒˆแ‹แŠ• value store แ‹จแˆแŠ“แˆจแŒแ‰ แ‰ต space แ‹ญแˆแŒ แˆซแˆแข

It is like แ‹จแˆ†แА แˆณแŒฅแŠ• แŠ แˆ‹แ‰ฝแˆ แŠฅแŠ•แ‰ แˆแฃ แŠจแ‹› แˆตแˆ แ‰ตแˆฐแŒกแ‰ณแˆ‹แ‰ฝแˆแฃ แŠฅแŠ“แˆ แ‹จแˆแˆˆแŒ‹แ‰ฝแˆแ‰ตแŠ• แАแŒˆแˆญ แˆณแŒฅแŠ‘ แ‹แˆตแŒฅ แˆ›แˆจแŒ แ‰ตแ‰ฝแˆ‹แˆ‹แ‰ฝแˆ so think the same way about variables.

x = 5

2. Variable Naming Rules:
-แ‹จvariable แˆฅแˆ แŠแ‹ฐแˆแฃ แ‰แŒฅแˆญ แŠฅแŠ“ underscore(_) แˆ˜แ‹ซแ‹ แ‹ญแ‰ฝแˆ‹แˆแข
- แ‹จvariable แˆฅแˆ แ‰ แ‰แŒฅแˆญ แˆ˜แŒ€แˆ˜แˆญ แŠ แ‹ญแ‰ปแˆแˆแข
- Variable names case-sensitive แŠ“แ‰ธแ‹แข แˆ›แˆˆแ‰ตแˆ แˆˆแˆแˆณแˆŒ age แŠฅแŠ“ Age แŠ แŠ•แ‹ต แŠ แ‹ญแАแ‰ต variable แŠ แ‹ญแ‹ฐแˆ‰แˆแข

my_variable = "Hello"

3. Data Types: Python is dynamically typed, แˆ›แˆˆแ‰ตแˆ แ‹จvariableแŠกแŠ• data type declare แˆ›แˆจแŒ แŠ แ‹ญแŒ แ‰ แ‰…แ‰ฅแŠ•แˆแข Python automatically แ‹จแˆšแŒˆแ‰ฃแ‹แŠ• data แ‰ แˆ›แ‹จแ‰ต แ‹จvariableแŠกแŠ• data type assign แ‹ซแˆจแŒ‹แˆแฃ แ‹ญแˆ„ แŒแŠ• แˆˆแˆแˆ‰แˆ programming languages แ‹จแˆšแˆฐแˆซ แŠ แ‹ญแ‹ฐแˆˆแˆแข

แˆˆแˆแˆณแˆŒแก difference in variable declaration between Java and Python แŠฅแŠ•แ‹ญแก

Declaring a variable in Java

int x = 5;

แ‰ แ‹šแˆ… แŒŠแ‹œ variable declare แˆตแŠ“แˆจแŒ data typeแŠกแŠ•แˆ assign แˆ›แˆจแŒ แ‹ญแŠ–แˆญแ‰ฅแŠ“แˆแข แŒแŠ• we don't need to do this in python, since it automatically assigns the type of data at the instant we give it a value.

Declaring a variable in Python:

x = 5

Let's assign different data types to a variable in python

x = 5  # x is an integer
y = 3.14 # y is a float
z = "Hello" # z is a string

4. Variable Reassignment: You can reassign a variable to a different value. แ‰ฐแˆแˆณแˆณแ‹ญ variable แ‰ แˆ˜แŒ แ‰…แˆ value reassign แˆ›แˆจแŒ แŠฅแŠ•แ‰ฝแˆ‹แˆˆแŠ•แฃ that means we can give it another value.

x = 5
x = 10 # x is now assigned the value 10
# x is no more 5

...แ‹ญแ‰€แŒฅแˆ‹แˆ

Practice by assigning different values for variables.

โ—Don't forget to invite your friendsโ—

@python_pioneers
@python_pioneers
๐Ÿ‘5๐Ÿ™2
Forwarded from Luna's pathway๐Ÿค— (Luna)
#Quote of the day
โค3
Multiple-choice questions pertaining to variable usage in Python.

โ“Test your knowledge about variables with the following questions โ“
2. Which of the following variable names is invalid in Python?
Anonymous Quiz
16%
a) my_variable
63%
b) 2nd_variable
11%
c) variable2
11%
d) _variable
3. What is the correct way to assign a value of 5 to a variable named "x" in Python?
Anonymous Quiz
87%
a) x = 5
3%
b) 5 = x
10%
c) x == 5
0%
d) x := 5
4. What happens if you try to access a variable that has not been defined in Python?
Anonymous Quiz
30%
a) It raises a SyntaxError
15%
b) It creates a new variable with that name
38%
c) It raises a NameError
17%
d) It returns None
๐Ÿ‘2
OPERATIONS IN PYTHON

Here are some of the fundamental operations in python. Mathematics แˆ‹แ‹ญ แŠซแ‹จแŠ• there are operations like addition , subtraction... แŠฅแАแ‹šแˆ…แŠ• operations Arithmetic operations แŠฅแŠ•แˆ‹แ‰ธแ‹‹แˆˆแŠ•แฃ Python แŒแŠ• Arithmetic operations แˆ‹แ‹ญ แ‹จแ‰ฐแŒˆแ‹ฐแ‰  แŠ แ‹ญแ‹ฐแˆˆแˆแฃ There are lots of operations.

Operands: Operands are the values or variables on which an operator acts. In other words, operands are the data that are manipulated by an operator in an expression.

แˆˆแˆแˆณแˆŒแก In the expression 5 + 3, the _operands_ are the numbers 5 and 3, while the plus sign (+) is the _operator_ that acts on the _operands_ to perform the addition operation.

แ‰  Python แ‹ฐแŒแˆž operands variables, constants, แ‹ˆแ‹ญแˆ expressions แˆŠแˆ†แŠ‘ แ‹ญแ‰ฝแˆ‹แˆ‰แข

1. Arithmetic Operations:

- Addition (+): แˆแˆˆแ‰ต แ‰แŒฅแˆฎแ‰ฝแŠ• แˆˆแˆ˜แ‹ฐแˆ˜แˆญ แ‹จแˆแŠ•แŒ แ‰€แˆ˜แ‹ type of operation แАแ‹แข.

- Subtraction (-): แŠจแˆ˜แŒ€แˆ˜แˆชแ‹ซแ‹ แ‰แŒฅแˆญ แˆแˆˆแ‰ฐแŠ›แ‹แŠ• แˆˆแˆ˜แ‰€แАแˆต แ‹จแˆšแ‹ซแŒˆแˆˆแŒแˆ operation แАแ‹แข

- Multiplication (*): แ‹ญแˆ…แŠ›แ‹ แ‹ฐแŒแˆž แˆแˆˆแ‰ต operands แˆˆแˆ›แ‰ฃแ‹›แ‰ตแก

- Division (/): แ‹จแˆ˜แŒ€แˆ˜แˆชแ‹ซแ‹แŠ• แ‰แŒฅแˆญ แ‰ แˆแˆˆแ‰ฐแŠ›แ‹ แ‰แŒฅแˆญ แˆˆแˆ›แŠซแˆแˆ แ‹ซแŒˆแˆˆแŒแˆ‹แˆ(The result is always a float).

- Modulus (%): Returns the remainder of the division(แ‰€แˆช return แ‹ซแˆจแŒ‹แˆ)

- Exponentiation (**): Raises the first operand to the power of the second.
x**y แˆ›แˆˆแ‰ต x to the power of y แŠฅแŠ•แ‹ฐ แˆ›แˆˆแ‰ต แАแ‹แข

- Floor Division (//): Returns the quotient without the remainder(แŠญแแˆแ‹แ‹ญ แ‹ซแˆˆ แ‰€แˆช return แ‹ซแˆจแŒ‹แˆ)

Code Example:

a = 10
b = 5
addition = a + b # result = 15

subtraction = a - b # result = 5

multiplication = a * b # result = 50

division = a / b # result = 2.0

modulus = a % b # result = 0 since the rem is 0

exponentiation = a ** b # result = 100000

floor_division = a // b # result = 2

2. Comparison Operations:

แŠฅแАแ‹šแˆ… operations แ‹ฐแŒแˆž แˆแˆˆแ‰ต values(operands) compare แ‰ แˆ›แ‹ตแˆจแŒ boolean value return แ‹ซแˆจแŒ‹แˆ‰ (True or False) based on on the comparison result.

- Equal (==): Checks if two operands are equal.

- Not Equal (!=): Checks if two operands are not equal.

- Greater Than (>): Checks if the first operand is greater than the second.

- Less Than (<): Checks if the first operand is less than the second.

- Greater Than or Equal To (>=): Checks if the first operand is greater than or equal to the second.

- Less Than or Equal To (<=): Checks if the first operand is less than or equal to the second.

Code Example:

x = 10
y = 5
equal = x == y # result = False since 10 != 5

not_equal = x != y # result = True since 10 != 5

greater_than = x > y # result = True since 10 > 5

less_than = x < y # result = False since 10 > 5

greater_than_or_equal_to = x >= y # result = True

less_than_or_equal_to = x <= y # result = False

...แ‹ญแ‰€แŒฅแˆ‹แˆ

@python_pioneers
@python_pioneers
๐Ÿ‘4๐Ÿ‘2
...contd

3. Logical Operations:

The operands here are boolean values (True and False).

- AND (and): Returns True if both operands are true.

- OR (or): Returns True if any of the operands are true.

- NOT (not): Returns True if the operand is false.

Code Example:

p = True
q = False
and_result = p and q # result = False
or_result = p or q # result = True
not_result = not p # result = False

4. Assignment Operations:
แŠฅแАแ‹šแˆ… แ‹ฐแŒแˆž แŠ แŠ•แ‹ตแŠ• value แˆˆvariable assign แˆˆแˆ›แ‹ตแˆจแŒ แАแ‹ แ‹จแˆแŠ•แŒ แ‰€แˆ˜แ‹แข

+= : แ‰ แ‰€แŠ แ‰ แŠฉแˆ แ‹ซแˆˆแ‹แŠ• operand แ‰ แŒแˆซ แ‰ แŠฉแˆ แ‰ฃแˆˆแ‹ operand แˆ‹แ‹ญ แ‹ญแ‹ฐแˆแˆญแŠ“ แ‹แŒคแ‰ฑแŠ• แ‰ แŒแˆซ แ‰ แŠฉแˆ แˆ‹แˆˆแ‹ operand assign แ‹ซแˆจแŒˆแ‹‹แˆแข

-= : แ‰ แ‰€แŠ แ‰ แŠฉแˆ แ‹ซแˆˆแ‹แŠ• operand แŠจแŒแˆซแ‹ แ‰ แˆ˜แ‰€แАแˆต แ‹แŒคแ‰ฑแŠ• แ‰ แŒแˆซ แ‰ แŠฉแˆ แˆ‹แˆˆแ‹ operand assign แ‹ซแˆจแŒ‹แˆแข


*= : แ‰ แŒแˆซ แ‰ แŠฉแˆ แ‹ซแˆˆแ‹แŠ• operand แ‰ แ‰€แŠ แ‰ แŠฉแˆ แ‰ฃแˆˆแ‹ แ‹ซแ‰ฃแ‹›แŠ“ แ‹แŒคแ‰ฑแŠ• แ‰ แŒแˆซ แ‰ แŠฉแˆ แˆ‹แˆˆแ‹ operand assign แ‹ซแˆจแŒ‹แˆแข

/= : แ‰ แŒแˆซ แ‰ แŠฉแˆ แ‹ซแˆˆแ‹แŠ• operand แ‰ แ‰€แŠ แ‰ แŠฉแˆ แ‰ฃแˆˆแ‹ operand แ‹ซแŠซแแˆแŠ“ แ‹แŒคแ‰ฑแŠ• แ‰ แŒแˆซ แ‰ แŠฉแˆ แˆ‹แˆˆแ‹ operand assign แ‹ซแˆจแŒˆแ‹‹แˆแข

Code Example:
x = 5
x += 3 # Equivalent to x = x + 3
x -= 2 # Equivalent to x = x - 2
x *= 4 # Equivalent to x = x * 4
x /= 2 # Equivalent to x = x / 2

These are just some of the basic operations in python, we believe you have grasped some knowledge about them.


@python_pioneers
@python_pioneers
๐Ÿ‘3โค1
GROW THROUGH WHAT YOU GO THROUGH.

แ‹จแˆšแ‹ซแŒ‹แŒฅแˆ˜แŠ• แˆ›แŠ•แŠ›แ‹แˆ แˆแ‰ฐแŠ“ แŠฅแŠ“ แˆ˜แˆฐแŠ“แŠญแˆ แˆˆแˆ˜แˆ›แˆญแฃ แˆˆแˆ›แ‹ฐแŒ แŠฅแŠ“ แˆˆแˆ˜แŒ แŠ•แŠจแˆญ แŠฅแ‹ตแˆ แ‹ญแˆฐแŒ แŠ“แˆแข แ‰ แˆšแ‹ซแŒ‹แŒฅแˆ™แŠ• แ‰ฝแŒแˆฎแ‰ฝ แŠจแˆ˜แˆ›แˆจแˆญ แ‹ˆแ‹ญแˆ แŠจแˆ˜แŠ“แ‹ฐแ‹ต แ‹ญแˆแ‰… แˆˆself development แŠฅแŠ“ แŠฅแˆซแˆณแ‰ฝแŠ•แŠ• แˆˆแˆ›แˆปแˆปแˆ แŠฅแŠ•แ‹ฐ แŠฅแ‹ตแˆ แŠ แ‹ตแˆญแŒˆแŠ• แˆ˜แ‰€แ‰ แˆ แŠ แˆˆแ‰ฅแŠ•แข

แˆ˜แˆแŠซแˆ แˆแˆฝแ‰ต!

@python_pioneers
๐Ÿ‘5๐Ÿฅฐ2
COMMENTS IN PYTHON

PythonแŠ• แ‰ แŠ แˆ›แˆญแŠ› แŠฅแŠ•แˆ›แˆญ!

Stay Tuned!
@python_pioneers
๐Ÿ‘2
Python Pioneers: A Beginner's Guide ๐Ÿ‡ช๐Ÿ‡น
COMMENTS IN PYTHON PythonแŠ• แ‰ แŠ แˆ›แˆญแŠ› แŠฅแŠ•แˆ›แˆญ! Stay Tuned! @python_pioneers
COMMENTS IN PYTHON

แ‰ Pythonแก Comments แ‰ Python interpreter ignore แ‹จแˆšแ‹ฐแˆจแŒ‰ แˆ›แ‰ฅแˆซแˆชแ‹ซแ‹Žแ‰ฝ แŠ“แ‰ธแ‹แข แ‹จแƒแแАแ‹แŠ• code purpose แˆˆแˆ˜แŒแˆˆแ…แฃ แŠฅแŠ•แ‹ดแ‰ต แŠฅแŠ•แ‹ฐแˆšแˆฐแˆซแฃ แŠฅแŠ“ แˆŒแˆŽแ‰ฝ แˆ˜แˆจแŒƒแ‹Žแ‰ฝแŠ• แˆˆแˆ˜แƒแ แŠฅแŠ•แŒ แ‰€แˆ›แ‰ธแ‹‹แˆˆแŠ•แข Comments are crucial for code readability and maintenance

TYPES OF COMMENTS IN PYTHONแก-

1. Single-Line Commentsแก แŠฅแАแ‹šแˆ… comments แ‰ # แˆแˆแŠญแ‰ต แ‹ญแŒ€แˆแˆซแˆ‰ แŠฅแŠ“ แŠฅแˆตแŠจ line แˆ˜แŒจแˆจแˆป แ‹ตแˆจแˆต แ‹ญแ‰€แŒฅแˆ‹แˆ‰ แข แŠฅแАแ‹šแˆ…แŠ• แ‹ฐแŒแˆž แˆˆแŠ แŒซแŒญแˆญ แˆ›แ‰ฅแˆซแˆชแ‹ซแ‹Žแ‰ฝ แŠฅแŠ•แŒ แ‰€แˆ›แ‰ธแ‹‹แˆˆแŠ•แข

    # This is a single-line comment
x = 5 # This is also a single-line comment

2. Multi-Line Commentsแก แ‰ Python แฃ แˆˆMulti-line comments specific syntax แ‹จแˆˆแˆแข แАแŒˆแˆญ แŒแŠ• แŠ แ‰ฅแ‹›แŠ›แ‹แŠ• แŒŠแ‹œ multi-line comments แˆˆแˆ˜แแŒ แˆญ triple qoutes(แˆถแˆตแ‰ต แ‰ตแˆแˆ…แˆญแ‰ฐ แŒฅแ‰…แˆต)(''' แ‹ˆแ‹ญแˆ """) แˆ˜แŒ แ‰€แˆ แŠฅแŠ•แ‰ฝแˆ‹แˆˆแŠ•แข

    '''
This is a multi-line comment.
It spans across multiple lines.
'''

3. Docstringsแก Docstringsแก functions, modules, แŠฅแŠ“ classes document แˆˆแˆ›แ‹ตแˆจแŒ แ‹ญแŒ แ‰…แˆ›แˆ‰แข They are enclosed in triple quotes and provide more detailed explanations of the purpose, parameters, and return values of functions.

แˆˆแˆแˆณแˆŒ แ‹ญแˆ„แŠ•แŠ• code แŠฅแŠ•แˆ˜แˆแŠจแ‰ตแก

    def add_numbers(a, b):
"""
This function adds two numbers together.

Parameters:
a (int): The first number.
b (int): The second number.

Returns:
int: The sum of a and b.
"""
return a + b

แŠฅแŠ“แˆ in general comments in any programming languages แ‹จแˆšแ‹ซแŒˆแˆˆแŒแˆ‰แ‰ต แ‹จแƒแแАแ‹ code แ‰ แˆแŠ• แ‹“แ‹ญแАแ‰ต แˆ˜แŠ•แŒˆแ‹ต แŠฅแŠ•แ‹ฐแˆšแˆฐแˆซ แˆˆแˆ˜แŒแˆˆแ… แАแ‹แฃ แ‹จแƒแแАแ‹แŠ• code แ‹ฐแŒแˆž แˆˆแˆ‹ แˆฐแ‹ แŠฅแŠ•แ‹ฒแ‹ซแ‹จแ‹ share แ‹จแˆแŠ“แˆจแŒ แŠจแˆ†แА แ‹จแˆšแ‹ซแАแ‰ แ‹ แˆฐแ‹ แ‹จแ‰ แˆˆแŒ  แˆตแˆˆ programแŠก แŠ แˆฐแˆซแˆญ แŠฅแŠ•แ‹ฒแˆจแ‹ณ แ‹ซแ‹ฐแˆญแŒ‹แˆแข

@python_pioneers
๐Ÿ‘3
There is no straight path to success. The problems we face have the ability to shape us. Grow through them.

HARD WORK
|
|
PROBLEM
|
SETBACK
|
FAILURE
|
CHALLENGE
|
OBSTACLE
|
|
SUCCESS

Have a nice day!

@python_pioneers
๐Ÿ‘1
Let's Revise what we have been learning with these questions.
๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡
1. What is the correct way to declare a variable in Python?
Anonymous Quiz
7%
A. var x = 5
67%
B. x = 5
25%
C. int x = 5
2%
D. declare x as 5
3. What type of operations can you perform on variables in Python?
Anonymous Quiz
12%
A. Mathematical operations
6%
B. String operations
0%
C. Logical operations
82%
D. All of the above