Unit 1 Notes Python

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Smart Engineer Babu

Python Programming
Unit-1(Full Explana on)

Topic-1: Python Programming Cycle.

Explana on: There are following points which helps us in understanding the Python Programming
Cycle-
1. Python’s programming cycle is shorter than other programming language cycles.
2. In Python, there are no compila on.
3. Python programs simply import modules at run me and use the objects they contain.
Because of this, Python programs run immediately a er changes are made.

4. Since Python is interpreted, there is a rapid turnaround a er program changes. And because
Python’s parser is embedded in Python-based systems, it is easy to modify programs at
run me.

Topic-2: IDE

Explana on:
1. It stands for Integrated Development Environment.
2. It is a so ware tool that helps programmer for developing and tes ng the so ware.
3. IDE was invented to make programming faster and efficient by diminish the coding and typing
errors.
4. Some Python IDEs are-

Topic-3: Interac on with Python program

Explana on: This chart shows the Interac on with Python Program-

Interpreter takes text commands and runs them as we enter text


Contextual informa on appears

Now enter some code for Python to run such as


print (“Hello World!”) and press the Enter key.

>>> print (“Hello World!”)


Output: Hello World!

Topic-4: Python, How Python is interpreted, the tools that help to find bugs or perform
sta c analysis and Python decorators.

Explana on: Python is a high level, interpreted, interac ve and object-oriented scrip ng language.
Python is easier language than any other programming language.

Interpreta on-
1. Interpreter is a kind of program that executes other programs.
2. Converts source code into machine under stable language.

Source Code interpreter Machine Code


3. A er that a .py file is generated and that is the main file of our program by which we can run
our program.

Tools that are used to find bugs in python-


1. Pychecker - It is an open-source tool for sta c analysis that detects the bugs from source
code and warns about the style and complexity of the bug.
2. Pylint – It also works same as Pychecker.

Python Decorators-
1. It allows programmers to modify the behaviour of func on or class.
2. It allows us to wrap another func on in order to extend the behaviour of wrapped func on,
without permanently modifying it.
3. Syntax :
@gfg_decorator
def hello_decorator():
print(“Gfg”)

4. gfg_decorator is a callable func on, will add some code on the top of some another callable
func on, hello_decorator func on and return the wrapper func on.

Topic-5: Comments in Python

Explana on:
1. Comment is the piece of code that programmer want to add in code but don’t want to
execute it that means,
2. Comment can be referred as extra text that shows extra informa on about code.
3. In python we represent comment with #.
Example-
>>> 8 + 9 # addi on

Topic-6: Iden fiers and keywords

Explana on: A Python iden fier is the name given to a variable, func on, class, module, or other
object that is used to access and iden fy the same. There are certain rules while naming a variable
that rules are following-
1. Iden fier always begin with an alphabet (A – Z or a – z) or underscore only.
2. A er that we can use alphabet, special symbols, numbers etc.
3. Python is a case-sensi ve language. Thus, Hello and hello both are different iden fiers. In
python, a class name will always start with a capital le er.

4. Python has a list of reserved words known as keywords. Every keyword has a specific purpose
and use. Some of them are following-
Topic-7: Variable and data-types.

Explana on:
Variable -
1. A variable holds a value that may change.
2. The process of wri ng the variable name is called declaring the variable.
3. In other language ‘int a’.
4. In python programming ‘a’.

Ini aliza on-


1. The general format of assignment statement is as follows:
Variable = Expression
2. The equal sign (=) is known as assignment operator.
3. The value of the expression will be stored in the variable.
Example->>>year=2016
>>> name= ‘Albert’

Data-Types-
1. The data stored in the memory can be of many types.
2. For example, a person’s name is stored as an alphabe c value and his address is stored as an
alphanumeric value.
3. Python has 6 basic data-types-
Numeric, String, List, Tuple, Dic onary, Boolean

4. Numeric- a=2
b=2.5
5. String- sample_string=”Hello”

Topic-8: list and tuple data-types.

Explana on:
List-
1.A list can contain the same type of items.
2.Alterna vely, a list can also contain different types of items.
3.A list is an ordered and indexable sequence.
4.To declare a list in Python, we need to separate the items using commas and enclose them
within square brackets ([ ]).
5. Opera ons such as concatena on, repe on and sub-list are done on list using plus (+),
asterisk (*) and slicing (:) operator.
6. For example:
>>>first = [1, “two”, 3.0, “four” ] # 1st list
>>>second = [“five”, 6] # 2nd list
>>>first # display 1st list
[1, ‘two’, 3.0, ‘four’] # Output
Tuple-
1. A tuple is also used to store sequence of items.
2. Like a list, a tuple consists of items separated by commas.
3. Tuples are enclosed within parentheses rather than within square brackets.
4. For example:
>>>third = (7, “eight”, 9, 10.0)
>>>third
(7, ‘eight’, 9, 10.0) # Output

Topic-9: Dic onary and Boolean data type.

Explana on:

Dic onary:
1. A dic onary is an unordered collec on of key-value pairs.
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
2. When we have the large amount of data, the dic onary data type is used.

Boolean:
1. In a Boolean variable we used to store the data in form of ‘yes’ and ‘no’.
2. ‘Yes’ is like ‘True’.
3. ‘No’ is like ‘False’.
4. For Example: a=’True’

Topic-10: Type conversion.

Explana on: The process of conver ng one data type into another data type is known as type
conversion. There are mainly two types of type conversion-

1. Implicit Type Conversion:


a. When the data type conversion takes place during compila on or during the run me,
then it called an implicit data type conversion.
b. Python handles the implicit data type conversion, so we do not have to explicitly convert
the data type into another data type.
2. Explicit type conversion:
a. Explicit type conversion is also known as type cas ng.
b. Explicit type conversion takes place when the programmer clearly and explicitly defines
the variables in the program.

Topic-11: Expression.

Explana on:
1. It is a combina on of symbols that evaluates to a value.
2. An expression is a combina on of variables, operators, values sub-expressions and a
reserve keyword.
3. Whenever we type an expression in the command line, the interpreter evaluates it and
produces the result.
4. Expressions that evaluate to a numeric type are called arithme c expressions.
5. A sub-expression is any expression that is part of a larger expression. Sub-expressions
are denoted by the use of parentheses.
For example : 4 + (3 * k) An expression can also consist of a single literal or variable.
Thus, 4, 3, and k are each expression. This expression has two sub-expressions, 4 and
(3 * k). Sub-expression (3 * k) itself has two sub-expressions, 3 and k.
Topic-12: Assignment Statement.

Explana on:
1. Assignment statements are used to create new variables, assign values, and change values.
2. Syntax of assignment operator-
Variable = Expression
3. There are three types of assignment statements:
a. Value-based expression on RHS-
test1 = “Hello”
a=23
b. Current variable on RHS-
current_var = “It’s Quantum Series”
new_var = current_var
c. Opera on on RHS-
test1 = 7 * 2 / 10

Topic-13: Operator.

Explana on:
1. An operator is a symbol that represents an opera on that may be performed on one or more
operands.
2. Operators are constructs used to modify the values of operands.
3. Operators that take one operand are called unary operators.
4. Operators that take two operands are called binary operators.
5. Based on func onality operators are categories into following seven types :
a. Arithme c operators.
b. Assignment operators.
c. Bitwise operators.
d. Comparison operators.
e. Iden ty operators.
f. Logical operators.
g. Membership operators.

Topic-14: All operators with example.

Explana on:
1. Arithme c Operators-
2. Comparison Operators-

3. Assignment Operators-
4. Bitwise Operators-

5. Logical Operators-

6. Iden ty Operators-
7. Membership Operators-

Topic-15: Operator Precedence.

Explana on:
1. When there is more than one operator in any expression then which operator executes first is
decided by Operator precedence.
2. Precedence of operator can also be stated as Importance or priority of Operator.
3. It is like Using BODMOS rule in maths.
For Example: Consider a mathema cal expression:
10+5/5
If the expression evaluated from,
L->R then answer = 3
R->L then answer = 11
4. We have a Table for determining the precedence of Operators that is following-
Topic-16: Operator associa vity.

Explana on:
1. Operator associa vity comes into role when two operators with same precedence occurs at
one expression.
2. To determine the execu on queue of operators with same precedency Operator associa vity
is used.

Operator
Associativity.

Left to Right Right to Left

3. Most of the operators in python follows L->R associa vity.


4. Some Operators which follow R->L are - =, +=, -=, *= , /=, %= , &=, ^= , |=, <<=, >>=
etc.
For example: 3 * 4 / / 6 result = 2
3 * (4 / / 6) result = 0

Topic-17: Boolean Expression.

Explana on: A Boolean expression may have only one of two values: True or False.
For example: 5 == 5 results = True
5 == 6 results = False

Topic-18: Memory Management in Python and PEP8

Explana on:
1. Memory management in python is done with the help of a heap that contains all python
objects and data structures.
2. This heap is managed by Python Memory Manager.

PEP8-
1. A PEP is a design document providing informa on to the Python community, or describing a
new feature for Python or its processes or environment.
2. PEP Stands for Python Enhancement Proposal.
Smart Engineer Babu smart_engineer_babu

You might also like