Learn Python from Scratch
Hello! Welcome
Together we will learn Python from scratch.
What is Python?
Python is an easy-to-use programming language and very popular.
With Python you can create programs quickly!
Why can you learn Python?
Python is easy to read and understand. It is perfect for both beginners and is used by technology companies around the world.
With Python you can create websites, analyze data, automate tasks and much more!
Installing Python
To start programming in Python, you first need to install Python on your computer.
Download it for free from its official website
You are doing great!
Now let’s talk about the syntax of Python.
Variables in Python
Variables in Python allow you to store information (For example, you can store numbers, texts, or lists of things)
age = 25
sum = age + 5
Python allows you to perform addition, subtraction, multiplication, and division easily, just like using a calculator.
Conditionals
Conditionals allow you to make decisions. With if, you can make Python do something only if a certain condition is met.
if age >= 18:
print("You are an adult.")
Loops
Loops allow you to repeat actions. With for or while, you can tell Python to repeat something several times.
for i in range(5):
print(i)
Functions
Functions are blocks of code that you can reuse.
def greet():
print("Hello from the function!")
You write the function once and can use it whenever you need.
Collections
Collections and structures allow us to store multiple data in a single variable! They are very powerful tools!
- Lists: They can be modified and allow duplicates.
my_list = [1, 2, 3]
- Tuples: Similar to lists, but they are immutable
my_tuple = (1, 2, 3)
- Sets: Collections of unique elements
my_set = {1, 2, 3}
- Dictionaries: Store key-value pairs
my_dict = {'name': 'Luis', 'age': 25}
You’re almost there!
We just need to see how to get started with Python.
Write your first code
A good first program is the classic “Hello, World”. Open a text editor or an IDE like IDLE or VS Code.
Write the following line of code:
print("Hello from LuisLlamas.es!")
This code will display a greeting on the screen!
How to run your code?
To run your code in Python, save the file with the .py
extension (for example, hello_world.py
)
Now ***open a command console*** in the folder where your file is located, and type ```bash python hello_world.py ```
Python will execute your file.
What is a library?
You can also divide your program into modules and libraries. They are groups of functions that we create to keep the code organized.
Python has a ton of public and free libraries! You can install them with the package manager PIP
Well done!
You now have the basics! Keep exploring and learning more about Python. The limit is your imagination!