بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ
Content
Python Basics:
Python Syntax
Comments
Variables
Data Types
Basic Operations
1. Python Syntax
- Python's syntax is essential for writing clear and efficient code. Python's syntax is designed to be readable and straightforward, which makes it an excellent language for beginners and experienced programmers alike.
Basic Syntax Rules
Case Sensitivity:
- Python is case-sensitive, meaning
Var
andvar
are two different identifiers.
Var = 10
var = 5
Indentation:
- Python uses indentation to define the structure of code blocks.
files = 6
if files > 5:
print("All files is installed")
2. Comments
- We use comments to Explain python code for anyone may be read the code and make code more readable
#This is a comment
- Multiline comment
"""
This
is
Multiline
comment
"""
3. Variables
Variables:
Variables are used to store data values.
You can create a variable simply by assigning a value to it.
- Example:
x = 10
name = "Ali"
3. Data Types
Python supports various data types, including integers, floats, strings, and Booleans.
Integers: Whole numbers, e.g.,
x = 10
Floats: Decimal numbers, e.g.,
pi = 3.14
Strings: Text, e.g.,
name = "Ahmed"
Booleans: True or False values, e.g.,
is_hacker = True
age = 21 # Integer
height = 5.9 # Float
name = "Ahmed" # String
is_hacker = True # Boolean
4. Basic Operations
In Python, you can perform a variety of basic operations with numbers and strings.
- These operations include arithmetic calculations, comparisons, and logical operations. Understanding these basic operations is crucial for writing effective Python programs.
Arithmetic Operations
- Addition Operation (
+
)
x = 10
y = 5
sum_num = x + y # 15
print(sum_num) # 15
- Subtraction (
-
)
diff_num = x - y # 5
- Multiplication (
*
)
multi_num = a * b # 50
- Division (
/
)
div_num = x / y # 2.0
- Floor Division (
//
): Divides one number by another and returns the largest whole number.
floor_div_num = x // y # 2
- Modulus (
%
): Returns the remainder of the division of two numbers.
mod_num = x % y # 0
- Exponentiation (
*
): Raises one number to the power of another.
exp_num = a ** b # 100000
Additional Resources
Check this section and solve practical exercise: Python Operators (w3schools.com)