What is Python :-
• Python is a dynamically typed, general-purpose programming language that supports an object-oriented
programming approach as well as a functional programming approach.
• Python is also an interpreted and high-level programming language.
• It was created by Guido Van Rossum in 1989.
Features of Python :-
• Python is simple and easy to understand.
• It is interpreted and platform-independent, which makes debugging very easy.
• Python is an open-source programming language.
• Python provides very big library support. Some of the popular libraries include NumPy, TensorFlow, Selenium,
OpenCV, etc.
• It is possible to integrate other programming languages within Python.
What is Python used for
• Python is used in data visualization to create plots and graphical representations.
• Python helps in data analytics to analyze and understand raw data for insights and trends.
• It is used in AI and machine learning to simulate human behavior and to learn from past data without hard
coding.
• It is used to create web applications.
• It can be used to handle databases.
• It is used in business and accounting to perform complex mathematical operations along with quantitative and
qualitative analysis.
What is Syntax?
In simplest words, Syntax is the arrangement of words and phrases to create well-formed sentences in a language. In the
case of a computer language, the syntax is the structural arrangement of comments, variables, numbers, operators,
statements, loops, functions, classes, objects, etc. which helps us understand the meaning or semantics of a computer
language.
For example, a ‘comment’ is used to explain the functioning of a block of code. It starts with a ‘#’.
More on comments in the comments chapter.
For example, a block of code is identified by an ‘indentation’. Have a look at the following code, here print(i) is said to be
indented with respect to the line above it. In simple words, indentation is the addition of spaces before the line print(i).
for i in range(5):
print(i)
Python Comments
A comment is a part of the coding file that the programmer does not want to execute. Rather, the programmer uses it to
either explain a block of code or to avoid the execution of a specific part of code while testing.
Single-Line Comments:
To write a comment, just add a # at the start of the line.
Example 1:
# This is a 'Single-Line Comment'
print("This is a print statement.")
Output:
This is a print statement.
Example 2:
print("Hello World !!!") # Printing Hello World
Output:
Hello World !!!
Example 3:
print("Python Program")
# print("Python Program")
Output:
Python Program
Multi-Line Comments:
To write multi-line comments, you can use # at each line or you can use the multiline string.
Example 1: The use of #.
# It will execute a block of code if a specified condition is true.
# If the condition is false then it will execute another block of code.
p=7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
Output:
p is greater than 5.
Example 2: The use of multiline string.
"""This is an if-else statement.
It will execute a block of code if a specified condition is true.
If the condition is false then it will execute another block of code."""
p=7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
Output:
p is greater than 5.
Python Variables
Variables are containers that store information that can be manipulated and referenced later by the programmer within
the code.
In Python, the programmer does not need to declare the variable type explicitly; we just need to assign the value to the
variable.
Example:
name = "Abhishek" # type str
age = 20 # type int
passed = True # type bool
It is always advisable to keep variable names descriptive and to follow a set of conventions while creating variables:
Variable names can only contain alphanumeric characters and underscores (A-z, 0-9, and _).
Variable names must start with a letter or the underscore character.
Variables are case sensitive.
Variable names cannot start with a number.
Scope of Variable:
The scope of the variable is the area within which the variable has been created. Based on this, a variable can either
have a local scope or a global scope.
Local Variable:
A local variable is created within a function and can only be used inside that function. Such a variable has a local scope.
Global Variable:
A global variable is created in the main body of the code and can be used anywhere within the code. Such a variable has
a global scope.
Python Data Types
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, Python data
types are classes and variables are instances (objects) of these classes. The following are the standard or built-in data
types in Python:
Numeric - int, float, complex
Sequence Type - string, list, tuple
Mapping Type - dict
Boolean - bool
Set Type - set, frozenset
Binary Types - bytes, bytearray, memoryview