🐍 Python Basics 1/6: Variables and Data Types
date
Mar 26, 2023
slug
python-basics-variables-and-data-types
status
Published
tags
Python Basics
summary
Learn how to declare variables and constants, what are the basics data types and operations, and how to input and output datas.
type
Post
Last updated
Mar 28, 2023 01:00 AM
👋 What's shaking, bacon? This is the first content of
Python Basics
module. This module does not have the goal to teeach you everything in Python, but to give you a glimpse of how the programming language works and to give you the basic knowledge to kick off your big adventure in Python. So, let's go!In this first class, we are going to learn how to declare variables and constants, what are the basics data types and operations, and how to input and output datas.
Oh, and you can get all the material in this GitHub Repo: python-basics-posts.
0) Declaring Variables and Constants! Basic Data Types!!
Python has five basics data types:
string
, integer
, float
, boolean
and complex number
.Besides, you can declare variables using the
=
operator, and encapsule the data by parenthesis ()
to transform a variable to a constant.#
# ---- Variables ----
#
my_string = "Hello World!"
my_integer = 42
my_float = 42.0
my_boolean = True # or False
my_complex_number = 4 + 2j # yeah, you have to use 'j' instead of 'i'
#
# ---- Constants ----
#
MY_STRING_CONST = ("Hello World!")
MY_INTEGER_CONST = (42)
MY_FLOAT_CONST = (42.0)
MY_BOOLEAN_CONST = (False)
MY_COMPLEX_NUMBER_CONST = (4 + 2j)
1) Basic Operators
Now, let's learn about the
math
, boolean
and bitwises
operators.#
# ---- Math Operators ----
#
addition = 2 + 2
subtraction = 4 - 5
multiplication = 8 * 5
division = 4 / 2
quocient = 3 // 2
power = 2 ** 5
modulus = 5 % 3
#
# ---- Boolean Operators ----
#
True and False
True or False
not True;
#
# ---- Bitwise Operators ----
#
and_bitwise = 5 & 2
or_bitwise = 5 | 2
xor_bitwise = 5 ^ 2
right_shift_bitwise = 5 << 2
left_shift_bitwise = 5 >> 2
2) Input and Output
For input, we are going to use
input
built-in function, and for output, guess what! We are not going to use output built-in function, because this one does not exist! We are gonna use print
instead!#
# ---- Input ----
#
my_input = input("Type anything:")
#
# ---- Output ----
#
print(f"My Input: {my_input}")
Well, hope you enjoyed this quick guide, and see you on the next one, where we will be learning about more complex data types, such as
lists
, dictionaries
and tuples
.See ya! 👋