What is python language
Python is general purpose, dynamic, object-oriented, interpreted and a high-level programming language known for its simple and easy-to-read syntax. This means that the code is much easier to write and we do not need to specify types in advance.
Python is used in web development, data analysis, artificial intelligence, machine learning, automation, and many more areas. It is also beginner-friendly, so it is quite popular for programmers.
Another major benefit of Python is that it has many libraries and frameworks available, such as Pandas (for data analysis), Django (for web development), and TensorFlow (for AI and machine learning).
Python was invented by Guido van Rossum in 1991 at CWI in Netherland. The idea of Python programming language has taken from the ABC programming language or we can say that ABC is a predecessor of Python language.
Why to use Python:
The following are the primary factors to use python in day-to-day life:
1. Python is object-oriented
Structure supports such concepts as polymorphism, operation overloading and
multiple inheritance.
2. Indentation
Indentation is one of the greatest feature in python
3. It’s free (open source)
Downloading python and installing python is free and easy
4. It’s Powerful
Dynamic typing
Built-in types and tools
Library utilities
Third party utilities (e.g. Numeric, NumPy, sciPy)
Automatic memory management
5. It’s Portable
Python runs virtually every major platform used today
As long as you have a compactable python interpreter installed, python
programs will run in exactly the same manner, irrespective of platform.
6. It’s easy to use and learn
No intermediate compile
Python Programs are compiled automatically to an intermediate form called
byte code, which the interpreter then reads.
This gives python the development speed of an interpreter without the
performance loss inherent in purely interpreted languages.
Structure and syntax are pretty intuitive and easy to grasp.
7. Interpreted Language
Python is processed at runtime by python Interpreter
8. Interactive Programming Language
Users can interact with the python interpreter directly for writing the programs
9. Straight forward syntax
The formation of python syntax is simple and straight forward which also makes it popular.
Writing first program:
# Script Begins
Statement1
Statement2
Statement3
# Script Ends
Installation:
Development Environment) which is installed when we install the python software
from http://python.org/downloads/
Steps to be followed and remembered:
Step 1: Select Version of Python to Install.
Step 2: Download Python Executable Installer.
Step 3: Run Executable Installer.
Step 4: Verify Python Was Installed On Windows.
Step 5: Verify Pip Was Installed.
Step 6: Add Python Path to Environment Variables (Optional)
Escape Sequence |
Usual Interpretation of Character(s) After Backslash |
“Escaped” Interpretation |
\' |
Terminates string with single quote
opening delimiter |
Literal single quote (') character |
\" |
Terminates string with double quote
opening delimiter |
Literal double quote (") character |
\newline |
Terminates input line |
Newline is ignored |
\\ |
Introduces escape sequence |
Literal backslash (\) character |
List:
· It is a
general purpose most widely used in data structures
· List is
a collection which is ordered and changeable and allows duplicate members.
(Grow and shrink as needed, sequence type, sortable).
· To use a
list, you must declare it first. Do this using square brackets and separate
values with commas.
· We can
construct / create list in many ways.
Ex: >>>
list1=[1,2,3,'A','B',7,8,[10,11]]
>>> print(list1)
[1, 2, 3, 'A', 'B', 7, 8, [10, 11]]
Rules for Python variables:
•
A variable name must start with a letter or the underscore character
•
A variable name cannot start with a number
•
A variable name can only contain alpha-numeric characters and underscores (A-z,
0-9, and _ )
•
Variable names are case-sensitive (age, Age and AGE are three different
variables)
Python ─ Basic Operators
Operators are the constructs which can manipulate the value
of operands.
·
Python Arithmetic Operators
Assume variable a holds 10 and variable b holds 20, then:
Operator |
Description |
Example |
+ |
Addition Adds values on either side of the operator. |
a + b = 30 |
- |
Subtraction Subtracts right hand operand from left hand
operand. |
a – b = -10 |
* |
Multiplication Multiplies values on either side of the
operator |
a * b = 200 |
/ |
Division Divides left hand operand by right hand operand |
b / a = 2 |
% Modulus |
Divides left hand operand by right hand operand and
returns remainder |
b % a = 0 |
·
Python Comparison Operators
These operators compare the values on either sides of them
and decide the relation among them. They are also called Relational operators.
Operator |
Description |
Example |
== |
If the values of two operands are equal, then the
condition becomes true. |
(a == b) is not true. |
!= |
If values of two operands are not equal, then condition becomes
true. |
(a != b) is true. |
<> |
If values of two operands are not equal, then condition
becomes true. |
(a <> b) is true. This is similar to != operator. |
> |
If the value of left operand is greater than the value of
right operand, then condition becomes true. |
(a > b) is not true. |
< |
If the value of left operand is less than the value of
right operand, then condition becomes true. |
(a < b) is true. |
>= |
If the value of left operand is greater than or equal to
the value of right operand, then condition becomes true. |
(a >= b) is not true. |
<= |
If the value of left operand is less than or equal to the
value of right operand, then condition becomes true. |
(a <= b) is true. |
·
Python Assignment Operators
Operator |
Description |
Example |
= |
Assigns values from right side operands to left side
operand |
c = a + b assigns value of a + b into c |
+= |
It adds right operand to the left operand and assign the
result to left operand |
c += a is equivalent to c = c + a |
-= |
It subtracts right operand from the left operand and
assign the result to left operand |
c -= a is equivalent to c = c - a |
*= |
It multiplies right operand with the left operand and
assign the result to left operand |
c *= a is equivalent to c = c * a |
/= |
It divides left operand with the right operand and assign
the result to left operand |
c /= a is equivalent to c = c / a |
0 Comments