Welcome back to “Python for Beginners” on BegunPro! In today’s blog post, we’ll dive into the fundamental building blocks of Python programming – variables, data types, and basic operations. If you’ve been following along, by now, you’ve set up Python and explored online editors. Today, let’s deepen our understanding of how Python handles data.
# Declare a variable
my_variable = 10
# Print the value of the variable
print(my_variable)
In the above snippet, my_variable
is a variable storing the value 10
. Python is dynamically typed, meaning you don’t have to explicitly mention the variable’s type; it’s inferred from the assigned value.
Data Types: int, float, and string
Python supports various data types, and three of the most basic ones are int
(integer), float
(floating-point number), and string
. Let’s explore each:
Integer (
int
): Whole numbers without any decimal points.
my_integer = 42
2. Float (float
): Numbers with decimal points or in exponential form.
my_float = 3.14
2.String (str
): Sequence of characters enclosed in single or double quotes.
my_integer = 42
my_float = 3.14
my_string = "Hello, Python!"
Basic Operations
Python allows you to perform various operations on these data types. Here are some basic operations:
Arithmetic Operations:
addition_result = 5 + 3
subtraction_result = 10 - 4
multiplication_result = 6 * 2
division_result = 8 / 2
- String Operation
greeting = "Hello"
name = "Alice"
combined_string = greeting + " " + name
- Type Conversion:
number_as_string = "42"
converted_number = int(number_as_string)
1 thought on “Python Learning Day 1-2”
Comments are closed.