Learn Python variables, data types, and operators. Practical examples and applications.
Working with data in Python starts with understanding the basics of the language, such as variables, data types, and operators. Variables allow you to store and manipulate data, data types define the type of information you store, and operators allow you to perform operations on that data.
In Python, variables are created automatically when we assign values. We don't have to declare their types up front, which makes the language very flexible.
x = 5 y = "Hello, World!" z = 3.14
When naming variables, it is worth following a few rules:
age = 30 Age = 25 _age = 40
Python supports several basic data types that are necessary for working with a variety of data.
int : integers
age = 25
float : floating point numbers
pi = 3.14
complex : complex numbers
complex_number = 2 + 3j
str : strings
name = "John Doe"
bool : logical values (True/False)
is_active = True
letter : letters
numbers = [1, 2, 3, 4, 5]
tuple : tuple
coordinates = (10.0, 20.0)
range : ranges
range_of_numbers = range(1, 10)
dict : dictionaries
person = { "name": "John", "age": 30, "city": "New York" }
Master data analysis in Python with my course.
You will master the basics of Python programming, including data types, variables, lists, dictionaries, functions, and error handling. You will learn to use the pandas library for advanced data analysis and work with different types of data. You will understand the process of analysis, exploration (EDA), and visualization. Creating your own functions will prepare you for job interviews and solving real-world business problems.
Python operators allow you to perform various operations on variables and values. Here are some of the most important types of operators:
They allow you to perform basic mathematical operations.
a = 10 b = 5 # Dodawanie print(a + b) # Output: 15 # Odejmowanie print(a - b) # Output: 5 # Mnożenie print(a * b) # Output: 50 # Dzielenie print(a / b) # Output: 2.0 # Modulo (reszta z dzielenia) print(a % b) # Output: 0 # Potęgowanie print(a ** b) # Output: 100000
They are used to compare values.
a = 10 b = 5 print(a == b) # Output: False print(a != b) # Output: True print(a > b) # Output: True print(a < b) # Output: False print(a >= b) # Output: True print(a <= b) # Output: False
They are used for logical operations.
a = True b = False print(a and b) # Output: False print(a or b) # Output: True print(not a) # Output: False
They are used to assign values to variables.
a = 10 a += 5 # To samo co a = a + 5 print(a) # Output: 15 a -= 3 # To samo co a = a - 3 print(a) # Output: 12 a *= 2 # To samo co a = a * 2 print(a) # Output: 24 a /= 4 # To samo co a = a / 4 print(a) # Output: 6.0
Understanding Python variables, data types, and operators is essential for working with data effectively. Python offers a simple and intuitive syntax that makes it easy to perform complex data manipulation. I hope this article has helped you understand the basics of Python and encouraged you to learn more. I encourage you to experiment with the code and discover how Python can make your work with data easier.
Prefer to read in English? No problem !
Other interesting articles:
That's all on this topic. Analyze in peace!
Did you like this article 🙂?
Share it on Social Media 📱
>>> share it on LinkedIn and show that you learn something new every day
>>> post it on Facebook , it might be useful to one of your friends
>>> Pin this page to your bookmarks, it may be useful in the future
You prefer watching 📺 than reading – no problem
>>> Follow and watch KajoData on YouTube