What is Python? 🐍
Python is a universal programming language created in 1991 by Guido van Rossum. It is simple, concise and readable. Python is used in web development, data analysis, artificial intelligence, automation, and even game development. 🎮
Why study Python? 🔥
Simplicity: clear and concise syntax.
Flexibility: you can write scripts, websites, work with data and create neural networks.
Large community: a huge amount of documentation and libraries.
Automation: helps to write scripts to simplify everyday tasks.
How to install Python? 💻
To work with Python, you will need:
✅ Python interpreter. You can download it from official website.
✅ Code editor. Recommended Visual Studio Code or PyCharm.
How to check if Python is installed? 🛠
Open the terminal and enter:
python --versionIf Python is installed, its version will appear.
Python Syntax Basics 📚
1. Variables 📦
In Python, variables are created simply:
Example of declaring variables:
name = "Alice" # Line
age = 25 # Integer
pi = 3.14 # Floating point number
print("Name:", name, "Age:", age, "Pi:", pi)2. Data output 📤
To display information, use print().
Example:
print("Hello, world!")3. Conditional operators (if...else) 🧐
Allow the program to make decisions.
Example:
age = 20
if age >= 18:
print("You're an adult!")
else:
print("You're still a child.")4. Loops (for, while) 🔄
Loops allow you to repeat actions.
Example:
for i in range(1, 6):
print(i)5. Functions 📐
Functions help to structure the code.
Example:
def square(x):
return x * x
print("Square of the number 5:", square(5))Simple projects in Python 💡
1. Random number generator 🎲
The program generates a random number from 1 to 100.
import random
number = random.randint(1, 100)
print("Random number:", number)2. Multiplication table 📊
The program displays a multiplication table from 1 to 10.
for i in range(1, 11):
for j in range(1, 11):
print(f"{i} x {j} = {i * j}")
print()3. Counting the number of characters in a string 🔢
The program counts the characters in the string.
text = "Hello, Python!"
print("Number of characters:", len(text))4. Checking the number for evenness 🔍
The program determines whether the number is even.
number = 42
if number % 2 == 0:
print(f"{number} - even number")
else:
print(f"{number} - odd number")5. Calculating the factorial of a number 🎯
This code calculates the factorial of a given number.
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
print("Factorial 5:", factorial(5))Conclusion 🎉
Python is a powerful programming language that is easy to learn. We have analyzed its basics: variables, input/output, conditions, loops and functions. Now you can write your first programs! 🚀
The more you practice, the better your code becomes. Experiment, try new tasks and master programming! Good luck learning Python! 😊
