python institute in Visakhapatnam
Python is one of the top programming languages in the world, widely used in fields such as AI, machine learning, data science, and web development.python training in vizag
The simple and English-like syntax of Python makes it a go-to language for beginners who want to get into coding quickly.python training in vizag
Because Python is used in multiple fields, there is a high demand for Python developers, with competitive base salaries.python training in vizag
Beginner’s Guide to Python
These lessons will provide you a strong foundation in Python and get you ready for your next professional move.
Is Python for you?
Python can be the best option for you depending on your objectives and career aspirations.
Best Way to Learn Python
There is no right or wrong way to learn Python. It all depends on your learning style and pace.
In this section, we have included the best Python learning resources tailored to your learning preferences, be it text-based, video-based, or interactive courses.python institute in Visakhapatnam
How to Get Started With Python?
python institute in Visakhapatnam
Getting Started with Python
Python is a versatile, high-level programming language that is widely supported across all major operating systems.
To execute Python code, you need to have a Python interpreter installed on your system. However, if you want to start immediately, you can use our free online Python editor that enables you to run Python code directly in your browser—no installation required.python training in vizag
For those who prefer to install Python on your computer, this guide will walk you through the installation process on Windows, macOS, and Linux (Ubuntu).python institute in Visakhapatnam
Install Python on Windows
To install Python on your Windows, just follow these steps:
- Install VS Code
- Download Python Installer File
- Run the Installer
- Install Python
- Verify your installation
Here is a detailed explanation of each of the steps:
Step 1: Install VS Code
Go to the VS Code Official website and download the Windows installer. Once the download is complete, run the installer and follow the installation process.python institute in Visakhapatnam
Click Finish to complete the installation process
Step 2: Download the Python Installer File
Go to the official Python website and download the latest version (Python 3.12.2 at the time of writing this tutorial) for Windows.
The website automatically detects your operating system and gives you the right installer.
Your First Python Program
In the previous tutorial, you learned how to install Python on your computer. Now, let’s write a simple Python program.
The following program displays Hello, World!
on the screen.
print("Hello, World!")
Output
Hello World!
Note: A Hello World!
program includes the basic syntax of a programming language and helps beginners understand the structure before getting started. That’s why it is a common practice to introduce a new language using a Hello World!
program.
Working of the Program
Congratulations on writing your first Python program. Now, let’s see how the above program works.
In Python, anything inside print()
is displayed on the screen.
There are two things to note about print()
:
- Everything we want to display on the screen is included inside the parentheses
()
. - The text we want to print is placed within double quotes
" "
.
We can also use single quotes to print text on the screen. For example,
print('Hello World!')
is same as
print("Hello World!")
To be consistent, we will be using double quotes throughout the tutorials.
Python Comments
In the previous tutorial, you learned to write your first Python program. Now, let’s learn about Python comments.
Important!: We are introducing comments early in this tutorial series because we will be using them to explain the code in upcoming tutorials.python institute in Visakhapatnam
Comments are hints that we add to our code to make it easier to understand. Python comments start with #
. For example,
# print a number
print(25)
Here, # print a number
is a comment.
Comments are completely ignored and not executed by code editors.
Important: The purpose of this tutorial is to help you understand comments, so you can ignore other concepts used in the program. We will learn about them in later tutorials.
Single-line Comment
We use the hash (#
) symbol to write a single-line comment. For example,
# declare a variable
name = "John"
# print name
print(name) # John
In the above example, we have used three single-line comments:
# declare a variable
# print name
# John
#
and extends up to the end of the line. We can also use single-line comments alongside the code:print(name) # John
Note: Remember the keyboard shortcut to apply comments. In most text editors, it’s Ctrl + / if you are on Windows & Cmd + / if you are on a Mac.
Multiline Comments
Unlike languages such as C++ and Java, Python doesn’t have a dedicated method to write multi-line comments.
However, we can achieve the same effect by using the hash (#
) symbol at the beginning of each line.
Let’s look at an example.
# This is an example of a multiline comment
# created using multiple single-line commenced
# The code prints the text Hello World
print("Hello, World!")
We can also use multiline strings as comments like:
'''This is an example
of multiline comment'''
print("Hello, World!")
Output
Hello World
Note: Remember you will learn about these programming concepts in upcoming tutorials. For now. you can just focus on the usage of comments.
Prevent Executing Code Using Comments
Comments are valuable when debugging code.python institute in Visakhapatnam
If we encounter an error while running a program, instead of removing code segments, we can comment them out to prevent execution. For example,
number1 = 10
number2 = 15
sum = number1 + number2
print("The sum is:", sum)
print("The product is:", product)
Here, the code throws an error because we have not defined a product variable. Instead of removing the line causing an error, we can comment it.
For example,
number1 = 10
number2 = 15
sum = number1 + number2
print("The sum is:", sum)
Output
The sum is 25
Here, the code runs without any errors.
We have resolved the error using a comment. Now if you need to calculate the product in the near future, you can uncomment it.
Note: This approach comes in handy while working with large files. Instead of deleting any line, we can use comments and identify which one is causing an error.python institute in Visakhapatnam
Why Use Comments?We should use comments:
- For future references, as comments make our code readable.
- For debugging.
- For code collaboration, as comments help peer developers to understand each other’s code.
Python Fundamentals
Python Variables and Literals
In the previous tutorial you learned about Python comments. Now, let’s learn about variables and literals in Python.
Python Variables
In programming, a variable is a container (storage area) to hold data. For example,
number = 10
Here, number is a variable storing the value 10.
Assigning values to Variables in PythonAs we can see from the above example, we use the assignment operator =
to assign a value to a variable.
# assign value to site_name variable
site_name = 'programiz.pro'
print(site_name)
# Output: programiz.pro
Output
apple.com
In the above example, we assigned the value programiz.pro
to the site_name variable. Then, we printed out the value assigned to site_name
Note: Python is a type-inferred language, so you don’t have to explicitly define the variable type. It automatically knows that programiz.pro
is a string and declares the site_name
variable as a string.
Changing the Value of a Variable in Python
site_name = 'programiz.pro'
print(site_name)
# assigning a new value to site_name
site_name = 'apple.com'
print(site_name)
Output
programiz.pro apple.com
Here, the value of site_name is changed from 'programiz.pro'
to 'apple.com'
.
Example: Assigning multiple values to multiple variables
a, b, c = 5, 3.2, 'Hello'
print (a) # prints 5
print (b) # prints 3.2
print (c) # prints Hello
If we want to assign the same value to multiple variables at once, we can do this as:
site1 = site2 = 'programiz.com'
print (x) # prints programiz.com
print (y) # prints programiz.com
Here, we have assigned the same string value 'programiz.com'
to both the variables site1 and site2.
Python Type Conversion
Python Type Conversion
In programming, type conversion is the process of converting data of one type to another. For example: converting int
data to str
.
There are two types of type conversion in Python.
- Implicit Conversion – automatic type conversion
- Explicit Conversion – manual type conversion
Python Implicit Type Conversion
In certain situations, Python automatically converts one data type to another. This is known as implicit type conversion.
Example 1: Converting integer to float
Let’s see an example where Python promotes the conversion of the lower data type (integer) to the higher data type (float) to avoid data loss.
integer_number = 123
float_number = 1.23
new_number = integer_number + float_number
# display new value and resulting data type
print("Value:",new_number)
print("Data Type:",type(new_number))
Output
Value: 124.23 Data Type: <class 'float'>
In the above example, we have created two variables: integer_number and float_number of int
and float
type respectively.
Then we added these two variables and stored the result in new_number.
Python Basic Input and Output
Python Output
In Python, we can simply use the print() function to print output. For example,
print('Python is powerful')
# Output: Python is powerful
Here, the print()
function displays the string enclosed inside the single quotation.
Syntax of print()
In the above code, the print()
function is taking a single parameter.
However, the actual syntax of the print function accepts 5 parameters
print(object= separator= end= file= flush=)
Here,
- object – value(s) to be printed
- sep (optional) – allows us to separate multiple objects inside
print()
. - end (optional) – allows us to add add specific values like new line
"\n"
, tab"\t"
- file (optional) – where the values are printed. It’s default value is
sys.stdout
(screen) - flush (optional) – boolean specifying if the output is flushed or buffered. Default:
False
Example 1: Python Print Statement
print('Good Morning!')
print('It is rainy today')
Output
Good Morning! It is rainy today
In the above example, the print()
statement only includes the object to be printed. Here, the value for end is not used. Hence, it takes the default value '\n'
.
So we get the output in two different lines.
Example 2: Python print() with end Parameter
# print with end whitespace
print('Good Morning!', end= ' ')
print('It is rainy today')
Output
Good Morning! It is rainy today
Notice that we have included the end= ' '
after the end of the first print()
statement.
Hence, we get the output in a single line separated by space.
Example 3: Python print() with sep parameter
print('New Year', 2023, 'See you soon!', sep= '. ')
Output
New Year. 2023. See you soon!
In the above example, the print()
statement includes multiple items separated by a comma.
Notice that we have used the optional parameter sep= ". "
inside the print()
statement.
Hence, the output includes items separated by .
not comma.
Example: Print Python Variables and Literals
We can also use the print()
function to print Python variables. For example,
number = -10.6
name = "Programiz"
# print literals
print(5)
# print variables
print(number)
print(name)
Output
5 -10.6 Programiz
Python Operators
Operators are special symbols that perform operations on variables and values. For example,
print(5 + 6) # 11
Here, +
is an operator that adds two numbers: 5 and 6.
Types of Python Operators
Here’s a list of different types of Python operators that we will learn in this tutorial.
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
- Special Operators
1. Python Arithmetic Operators
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc. For example,python institute in Visakhapatnam
sub = 10 - 5 # 5
Here, -
is an arithmetic operator that subtracts two values or variables.
Operator | Operation | Example |
---|---|---|
+ | Addition | 5 + 2 = 7 |
- | Subtraction | 4 - 2 = 2 |
* | Multiplication | 2 * 3 = 6 |
/ | Division | 4 / 2 = 2 |
// | Floor Division | 10 // 3 = 3 |
% | Modulo | 5 % 2 = 1 |
** | Power | 4 ** 2 = 16 |
Example 1: Arithmetic Operators in Python
a = 7
b = 2
# addition
print ('Sum: ', a + b)
# subtraction
print ('Subtraction: ', a - b)
# multiplication
print ('Multiplication: ', a * b)
# division
print ('Division: ', a / b)
# floor division
print ('Floor Division: ', a // b)
# modulo
print ('Modulo: ', a % b)
# a to the power b
print ('Power: ', a ** b)
Output
Sum: 9 Subtraction: 5 Multiplication: 14 Division: 3.5 Floor Division: 3 Modulo: 1 Power: 49
In the above example, we have used multiple arithmetic operators,
+
to adda
andb
-
to subtractb
froma
*
to multiplya
andb
/
to dividea
byb
//
to floor dividea
byb
%
to get the remainder**
to geta
to the powerb
Python Flow Control
Python if…else Statement
Python for Loop
Python while Loop
Python break and continue
Python pass Statement
Python Data Types
Python Numbers, Type Conversion and Mathematics
Python List
Python Tuple
Python Sets
Python Dictionary
Python Functions
Python Functions
Python Function Arguments
Python Variable Scope
Python Global Keyword
Python Recursion
Python Modules
Python Package
Python Main function
Python Files
Python Directory and Files Management
Python CSV: Read and Write CSV files
Reading CSV files in Python
Writing CSV files in Python
Python Exception Handling
Python Exceptions
Python Exception Handling
Python Custom Exceptions
Python Object and Class
Python Objects and Classes
Python Inheritance
Python Multiple Inheritance
Polymorphism in Python
Python Operator Overloading
Python Advanced Topics
List comprehension
Python Lambda/Anonymous Function
Python Iterators
Python Generators
Python Namespace and Scope
Python Closures
Python Decorators
Python @property decorator
Python RegEx
Python Date and Time
Python datetime
Python strftime()
Python strptime()
How to get current date and time in Python?
Python Get Current Time
Python timestamp to datetime and vice-versa
Python time Module
Python sleep()
Additional Topic
Precedence and Associativity of Operators in Python
Python Keywords and Identifiers
Python Asserts
Python Json
Python pip
Python *args and **kwargs