βPython is a versatile, high-level programming language known for its readability and simplicity. Whether you’re a beginner or an experienced developer, Python offers a wide range of functionalities that make it a popular choice in various domains such as web development, data science, artificial intelligence, and more. βIn this article, we’ll cover the foundational concepts of Python programming to help you get started.
Writing First Python Program
To begin coding in Python, we’ll need to have Python installed on our system. You can download the latest version from the official Python website. Once installed, we can write and execute Python code using an Integrated Development Environment (IDE) like PyCharm, Vs Code (requires installing Python extension), or even a simple text editor.
Python
print("Hello Geeks, Welcome to Python Basics")
OutputHello Geeks, Welcome to Python Basics
Explanation: print() is a built-in function that outputs text or variables to the console. In this case, it displays the string “Hello, Geeks! Welcome to Python Basics”.
Comments in Python
Comments in Python are the lines in the code that are ignored by the interpreter during the execution of the program. Also, Comments enhance the readability of the code and help the programmers to understand the code very carefully.
Python
# This is a single-line comment
"""
This is a
multi-line comment
or docstring.
"""
Explanation:
- #: Denotes a single-line comment.β
- “”” “”” or ”’ ”’: Triple quotes are used for multi-line comments or docstrings.
Variables in Python
Python Variable is a container that store values. Python is not βstatically typedβ. An Example of a Variable in Python is a representational name that serves as a pointer to an object. Once an object is assigned to a variable, it can be referred to by that name.
Rules for Naming Variables
- Must start with a letter (a-z, A-Z) or an underscore (_).β
- Cannot start with a number.β
- Can only contain alphanumeric characters and underscores.β
- Case-sensitive (name, Name, and NAME are different variables).β
- The reserved words(keywords) in Python cannot be used to name the variable in Python.
Example:
Python
# Integer assignment
age = 45
# Floating-point assignment
salary = 1456.8
# String assignment
name = "Geek"
print(age)
print(salary)
print(name)
Data Types in Python
Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are classes and variables are instances (objects) of these classes.

Example: This code assigns variable βxβ different values of various data types in Python.
Python
x = "Hello World" # string
x = 50 # integer
x = 60.5 # float
x = 3j # complex
x = ["geeks", "for", "geeks"] # list
x = ("geeks", "for", "geeks") # tuple
x = {"name": "Suraj", "age": 24} # dict
x = {"geeks", "for", "geeks"} # set
x = True # bool
x = b"Geeks" # binary
Python provides simple functions for input and output operations.β
Input
The input() function allows user input, example:
Python
val = input("Enter your value: ")
print("You entered:", val)
Output:
Enter your value: 11
You entered: 11
The input() function in Python always returns data as a string, regardless of what the user enters. If we want to store the input as another data type (like int, float, etc.), we need to explicitly convert (typecast) it.
Example:
Python
name = input("Enter your name: ")
print(type(name))
age = int(input("Enter your age: "))
print(type(age))
Output:
Enter your name: Geeks
<class 'str'>
Enter your age: 8
<class 'int'>
Explanation:
- name stores the input as a string (default behavior of input()).
- age stores the input as an integer using int() for typecasting.
Python
# Python program show input and Output
val = input("Enter your value: ")
print(val)
Python Operators
In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for the purpose of logical and arithmetic operations. In this article, we will look into different types of Python operators.
Arithmetic Operators
Python Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication, and division. Types of arithmetic operators: +, -, *, /, //, %, **β
Precedence of Arithmetic Operators
The precedence of Arithmetic Operators in Python is as follows:
- P β Parentheses
- E β Exponentiation
- M β Multiplication (Multiplication and division have the same precedence)
- D β Division
- A β Addition (Addition and subtraction have the same precedence)
- S β Subtraction
Example:
Python
a = 9
b = 4
add = a + b
sub = a - b
mul = a * b
mod = a % b
E = a ** b
print(add)
print(sub)
print(mul)
print(mod)
print(E)
Comparison Operators
Comparison operators are used to compare two values. They return a Boolean value β either True or False β depending on whether the comparison is correct. These operators are often used in conditional statements like if, while, and loops.
Example:
Python
a = 10
b = 20
print(a == b) # False, because 10 is not equal to 20
print(a != b) # True, because 10 is not equal to 20
print(a > b) # False, 10 is not greater than 20
print(a < b) # True, 10 is less than 20
print(a >= b) # False, 10 is not greater than or equal to 20
print(a <= b) # True, 10 is less than or equal to 20
OutputFalse
True
False
True
False
True
Explanation:
- Each print() checks a condition.
- The result is either True or False depending on whether the comparison holds.
- These operators are commonly used to control program flow in if statements, loops, etc.
Logical Operators
Python Logical operators perform Logical AND , Logical OR , and Logical NOT operations. It is used to combine conditional statements. Types of logicsl operators: and, or, notβ.
Python
a = True
b = False
print(a and b)
print(a or b)
print(not a)
Bitwise Operators
Python Bitwise operators act on bits and perform bit-by-bit operations. These are used to operate on binary numbers. Types of bitwise operators: &, |, ^, ~, <<, >>β
Python
a = 10
b = 4
print(a & b)
print(a | b)
print(~a)
print(a ^ b)
print(a >> 2)
print(a << 2)
Assignment Operators
Python Assignment operators are used to assign values to the variables. Types of assignment operators: =, +=, -=, *=, /=, %=, **=, //=, &=, |=, ^=, >>=, <<=β.
Python
a = 10
b = a
print(b)
b += a
print(b)
b -= a
print(b)
b *= a
print(b)
b <<= a
print(b)
Output10
20
10
100
102400
Python If Else
In Python, the if statement is used to run a block of code only when a specific condition is true. If the condition is false and you want to run a different block of code, you can use the else statement. This allows your program to make decisions and respond differently based on conditions.
Example 1: Python IF-Else
Python
i = 20
if (i < 15):
print("i is smaller than 15")
print("i'm in if Block")
else:
print("i is greater than 15")
print("i'm in else Block")
print("i'm not in if and not in else Block")
Outputi is greater than 15
i'm in else Block
i'm not in if and not in else Block
Explanation:
- The condition i < 15 is False, so the else block is executed.
- The last print() runs no matter what because it’s outside the if-else structure.
Example 2: Python if-elif-else ladder
Sometimes, weneed to check multiple conditions. In such cases, Python provides the if-elif-else structure.
Python
i = 20
if (i == 10):
print("i is 10")
elif (i == 15):
print("i is 15")
elif (i == 20):
print("i is 20")
else:
print("i is not present")
Explanation:
- Python checks conditions from top to bottom.
- Once a condition is True, it executes that block and skips the rest.
- If none of the conditions match, it executes the else block.
Python Loops
For Loop
Python For loop is used for sequential traversal i.e. it is used for iterating over an iterable like String, Tuple, List, Set, or Dictionary. Here, we will see a “for” loop in conjunction with the range() function to generate a sequence of numbers starting from 0, up to (but not including) 10, and with a step size of 2. For each number in the sequence, the loop prints its value using the print() function.
Python
for i in range(0, 10, 2):
print(i)
Explanation:
- range(0, 10, 2) generates numbers: 0, 2, 4, 6, 8.
- The loop prints each number on a new line.
While Loop
A while loop continues to execute as long as a condition is True. In this example, the condition for while will be True as long as the counter variable (count) is less than 3.
Python
count = 0
while (count < 3):
count = count + 1
print("Hello Geek")
OutputHello Geek
Hello Geek
Hello Geek
Explanation:
- The loop runs 3 times because count goes from 0 – 1 – 2.
- Once count becomes 3, the condition count < 3 becomes False and the loop stops.
Also see: Use of break, continue and pass in Python
Python Functions
Python Function is a block of reusable code that performs a specific task. Functions help make your code modular, readable, and easier to debug.
There are two main types of functions in Python:
- Built-in functions like print(), len(), type()
- User-defined functions created using the def keyword

Example: User-Defined Function to Check Even/Odd
Python
def evenOdd(x):
if x % 2 == 0:
print("even")
else:
print("odd")
evenOdd(2)
evenOdd(3)
Explanation:
- The function evenOdd(x) checks if x is divisible by 2.
- If it is, it prints “even”; otherwise, “odd”.
What’s Next
After understanding the Python Basics, there are several paths you can explore to further enhance your skills and delve deeper into the language:
- Continuous Python Learning : This article offers a well-organized, in-depth tutorial on Python, guiding learners from the basics to more advanced topics.
- Advanced Python Concepts : This article covers some advance Python concepts that distinguishes Python from any other language such as list comprehenison, lambda function, etc.
- Python Packages and Frameworks : Python has a rich ecosystem of libraries and frameworks for a wide range of tasks such as web development with frameworks like Django or Flask, data analysis and visualization with libraries like Pandas and Matplotlib, machine learning and artificial intelligence with TensorFlow or PyTorch, or automation with libraries like Selenium or BeautifulSoup This article explores them in detail.
- Build Python Projects : Learn how to build real-world applications using Python. This section includes a variety of projects to help you apply your skills and create meaningful solutions.
Similar Reads
How to Learn Python Basics With ChatGPT
Python is one of the most popular programming languages, known for its simplicity and versatility. Whether you're a complete beginner or an experienced programmer looking to expand your skillset, mastering the basics of Python is essential. In this guide, we'll walk you through the fundamentals of P
4 min read
How to Learn Python in 21 Days
At present, Python is one of the most versatile and demanded programming languages in the IT world. Statistically, there are around 8-9 Million Python developers across the world and the number is increasing rapidly. Meanwhile, the average salary of an Entry-Level Python Developer in India is around
9 min read
Python Crash Course
If you are aware of programming languages and ready to unlock the power of Python, enter the world of programming with this free Python crash course. This crash course on Python is designed for beginners to master Python's fundamentals in record time! Experienced Python developers developed this fre
7 min read
10 Best Beginner's Tips for Learning Python
Python is a high-level, interpreted, general-purpose programming language that supports both object-oriented programming and structured programming. It is quite versatile and offers a lot of functionalities using standard libraries which allows the easy implementation of complex applications. Python
4 min read
FREE Python Course For Beginners
Whether you're seeking a career in Machine Learning or Data Science or Website Development - the knowledge of Python Language is very much relevant in all these domains. And as it is widely used in numerous areas, Python is preferred by almost every tech giant out there such as Google, Facebook, You
4 min read
Free Python Course Online [2025]
Want to learn Python and finding a course for free to learn Python programming? No need to worry now, Embark on an exciting journey of Python programming with our free Python course- Free Python Programming - Self-Paced, which covers everything from Python fundamentals to advanced. This course is pe
6 min read
Python Course Syllabus
Hereâs a straight-to-the-point breakdown of what a python course covers from the basics to advanced concepts like data handling, automation and object-oriented programming. No fluff, just the essentials to get you coding fast. Getting Started with Python ProgrammingWelcome to the getting started wit
6 min read
How to Learn Python from Scratch in 2025
Python is a general-purpose high-level programming language and is widely used among the developersâ community. Python was mainly developed with an emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. If you are new to programming and want to le
15+ min read
How to Become a Python Developer in 2024
To keep up with technological advancement, you've to stay updated with the latest trends it follows. All your morning-to-night scrolls done on an application is dependent on a programming language. Python has proved itself better in all its ways be it its versatility, simplicity, and flexibility. No
11 min read
Best Way To Start Learning Python - A Complete Roadmap
Python...The world's fastest-growing and most popular programming language not just amongst software engineers but also among mathematicians, data analysts, scientists, accountants, network engineers, and even kids! because it's a very beginner-friendly programming language. People from different di
10 min read