Python for Beginners: Part 2 — Data Types, Operators, and Basic Syntax

Sharmasaravanan
2 min readMar 1, 2023

--

Welcome back to Part 2 of our Python tutorial series for beginners. In this post, we will cover the basic data types, operators, and syntax in Python.

Data Types

Python has several built-in data types, including integers, floats, strings, booleans, and lists. Let’s take a look at each one in more detail:

  • Integers are whole numbers, such as 1, 2, 3, etc.
  • Floats are decimal numbers, such as 1.0, 2.5, 3.14159, etc.
  • Strings are sequences of characters, enclosed in single or double quotes, such as “hello”, ‘world’, etc.
  • Booleans are True or False values.
  • Lists are collections of values, enclosed in square brackets, such as [1, 2, 3], [‘hello’, ‘world’], etc.

Operators

Operators are symbols or keywords that perform operations on values. Python has several built-in operators, including arithmetic operators, comparison operators, and logical operators.

Arithmetic operators perform basic math operations, such as addition, subtraction, multiplication, division, and modulus:

# arithmetic operators
a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.3333333333333335
print(a % b) # 1

Comparison operators compare two values and return a boolean value, either True or False:

# comparison operators
x = 5
y = 10
print(x == y) # False
print(x != y) # True
print(x < y) # True
print(x > y) # False
print(x <= y) # True
print(x >= y) # False

Logical operators perform logical operations on boolean values:

# logical operators
a = True
b = False
print(a and b) # False
print(a or b) # True
print(not a) # False

Syntax

Python uses indentation to delimit blocks of code. Blocks are typically defined by control structures, such as if statements, loops, and functions. Here’s an example:

# if statement
x = 10
if x > 0:
print("x is positive")
else:
print("x is non-positive")

In this example, we use an if statement to check if x is greater than 0. If it is, we print “x is positive”. Otherwise, we print “x is non-positive”. Note the indentation of the print statements. The code within the if statement is indented to show that it is a block of code.

That’s it for Part 2. In the next part of this series, we will learn about control structures, functions, and modules in Python.

Stay tuned for more!

I am always happy to connect with my followers and readers on LinkedIn. If you have any questions or just want to say hello, please don’t hesitate to reach out.

https://www.linkedin.com/in/sharmasaravanan/

Happy learning!

Adios, me gusta!! 🤗🤗

#Python #Beginners #DataTypes #Operators #Syntax #Programming #Technology #Blog

--

--

Sharmasaravanan
Sharmasaravanan

Written by Sharmasaravanan

Versatile AI/ML maestro with 500+ deployed microservices for image/text processing. AWS and CI/CD virtuoso. Crafting the future, one line of code at a time. ✨