PL Variable, Data Types and Operators in Python

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.

Variables in Python

Creating and assigning value

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

Variable naming

When naming variables, it is worth following a few rules:

 age = 30 Age = 25 _age = 40

Data types in Python

Python supports several basic data types that are necessary for working with a variety of data.

Number types

int : integers

 age = 25

float : floating point numbers

 pi = 3.14

complex : complex numbers

 complex_number = 2 + 3j

Text types

str : strings

 name = "John Doe"

Logical types

bool : logical values (True/False)

 is_active = True

Sequential types

letter : letters

 numbers = [1, 2, 3, 4, 5]

tuple : tuple

 coordinates = (10.0, 20.0)

range : ranges

 range_of_numbers = range(1, 10)

Mapping types

dict : dictionaries

 person = {    "name": "John",    "age": 30,    "city": "New York" }
Python Data Analysis Course

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

Python operators allow you to perform various operations on variables and values. Here are some of the most important types of operators:

Arithmetic 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

Comparison operators

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

Logical operators

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

Assignment operators

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

Python Basic Operations Checklist

  1. Creating Variables : Assigning values to variables.
  2. Variable naming : Rules for creating variable names.
  3. Data types : int, float, str, bool, list, tuple, dict.
  4. Arithmetic operators : +, -, *, /, %, **.
  5. Comparison operators : ==, !=, >, <, >=, <=.
  6. Logical operators : and, or, not.
  7. Assignment operators : =, +=, -=, *=, /=.

Summary

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