0% found this document useful (0 votes)
11 views25 pages

Python First2Unit TM

The document provides an overview of algorithms, including their definitions, properties, and methods for development. It discusses building blocks such as statements, control flow, and functions, as well as the advantages and disadvantages of pseudo code and flowcharts. Additionally, it covers concepts of iteration, recursion, and object-oriented programming, highlighting their significance in problem-solving and programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views25 pages

Python First2Unit TM

The document provides an overview of algorithms, including their definitions, properties, and methods for development. It discusses building blocks such as statements, control flow, and functions, as well as the advantages and disadvantages of pseudo code and flowcharts. Additionally, it covers concepts of iteration, recursion, and object-oriented programming, highlighting their significance in problem-solving and programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT I

Algorithms
An algorithm is a step by step procedure of solving a problem. The word “algorithm”
is derived from the name of the 9th century Persian mathematician Al- Khwarizmi.
An algorithm is defined as a collection of unambiguous instructions which are
executed in a specific sequence to produce an output in a finite amount of time for a
given set of input data.
An algorithm can be written in English or in any standard representation. An
algorithm must possess the following properties
Finiteness: An algorithm must be executed finite number of times.
Definiteness: Each step of the algorithm must be accurate and clear.
Effectiveness: Each step must be effective, in the sense that it should be primitive
(easily convertible into a program statement) and can be performed exactly in a finite
amount of time.
Independent: The algorithm must be independent of any programming code.
Input/output: Each algorithm must take zero or more quantities as input data and
give out one or more output values.

Methods for Developing an Algorithm


List the data needed to solve the problem (input) and know what is the end result
(output).
Describe the various step to process the input to get the desired output. Break down
the complex processes into simpler statements.
Finally test the algorithm with different data sets. Example: Algorithm for Addition of
two numbers:
Step1: Start
Step 2: Get two numbers a and b as input
Step 3: Add the numbers a & b and store the result in c
Step 4: Print c
Step 5: Stop.
The above algorithm is to add two numbers a and b. The numbers are the input
provided by the user .After adding the result is stored in a variable c and it is printed.
Building Blocks of Algorithm:
The basic building blocks of an algorithm are Statements, Control flow and
Functions.
Statements: Statement may be a single action in a computer. In a computer
statements might include some of the following actions
input data-information given to the program
process data-perform operation on a given input
output data-processed result
Control flow: The process of executing the statements in the given sequence is
called as control flow.

The three ways in executing the control flow are


1. Sequence
2. Selection
3. Iteration
Sequence
The given set of instructions executed consecutively is called sequence execution.
Example: Algorithm to find the average of three numbers, the algorithm is as follows
Step1: Start
Step2: Get three numbers a, b, c as input Step3: Find the sum of a, b and c
Step4: Divide the sum by 3
Step5: Store the result in variable d Step6: Print d
Step7: Stop
The above algorithm finds the average of three numbers a, b and c. The numbers
are the input provided by the user .After adding the total is divided by 3 and the
result is stored in a variable d and it is printed.
Selection
A selection statement is transferring the program control to a specific part of the
program based upon the condition.
If the condition is true, one part of the program will be executed, otherwise the other
part of the program will be executed.
Example: Algorithm to find the Largest of two numbers, the algorithm is as follows
Step1: Start
Step 2: Get two numbers a and b as input
Step 3: IF a>b THEN
Step 4: PRINT “A is Large”
Step 5: ELSE PRINT “B is Large”
Step 6: ENDIF
Step 7: Stop
The above algorithm is used to find the Largest of two numbers a and b. The
numbers are the input provided by the user .The number a and b are compared, If a
is larger Print “A is Large” or if b is larger print “B is Large”.
Iteration
Iteration is a type of execution where a certain set of statements are executed again
and again based upon condition. This type of execution is also called as looping or
repetition.
Example: Algorithm to print all natural numbers up to n, the algorithm is as follows
Step 1: Start
Step 2: Get the value of n.
Step 3: Initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 7
Step 5: Print i value and increment i value by 1
Step 6: Go to step 4
Step 7: Stop
The above algorithm is for printing first n natural numbers .The user provides the
input. The first value, i is initialized. A loop is initialized. The first value is printed and
the number is incremented. The i value is checked with n, the user input. The
numbers are printed until i becomes greater than n.
Functions
Function is a sub program which consists of block of instructions that performs a
particular task. For complex problems, the problem is been divided into smaller and
simpler tasks during algorithm design.
Benefits of Using Functions
 Reduction in line of code
 code reuse
 Better readability
 Information hiding
 Easy to debug and test
 Improved maintainability
Example: Algorithm for addition of two numbers using function Main function ()
Step 1: Start
Step 2: Call the function add ()
Step 3: Stop
The above algorithm is to call the function add. This function is called as Main
function or calling function.
Subfunction add ()
Step 1: Function start
Step 2: Get two numbers as input and store it in to a and b
Step 3: Add the numbers a & b and store the result in c
Step 4: Print c
Step 5: Return.
The above algorithm is called as the called function which is to add two numbers a
and b. The numbers are the input provided by the user .After adding the result is
stored in a variable c and it is printed.
NOTATIONS
Pseudo Code
Pseudo –False.
Code- Set of Instructions.
Pseudo code means a short, readable set of instructions written in English to explain
an algorithm.
Rules for writing Pseudo code
Write one statement per line
Capitalize keywords.
Indent to hierarchy.
Keep statements language independent.

Common keywords used in writing a Pseudo code


Comment: //
Start: BEGIN Stop: END
Input: INPUT, GET, READ
Calculate: COMPUTE, CALCULATE, ADD, SUBTRACT, INITIALIZE Output:
OUTPUT, PRINT, DISPLAY
Selection: IF, ELSE, ENDIF
Iteration: WHILE, ENDWHILE, FOR, ENDFOR
Example: Pseudo code to Add two numbers

BEGIN
GET a, b
ADD c=a+b
PRINT c
END

Advantages:
 Pseudo code is program independent.
 It is easily understandable by layman.
 There is no Standard syntax.
 Pseudo code cannot be compiled or executed.
 It is easy to translate pseudo code into a programming language.
 It can be easily modified as compared to flowchart.
Disadvantages:
 It is not visual.
 We do not get a picture of the design.
 There is no standardized style or format.
 For a beginner, it is more difficult to follow the logic or write pseudo code as
compared to flowchart.

Flow Chart
Flow chart is defined as the graphical or diagrammatical representation of the
process of solving a problem. It represents the steps of a process in a sequential
order.
Solving Rules:
The flowchart should be clear, neat and easy to follow.
The flowchart must have a logical start and finish.
Only one flow line should come out from a process symbol
Only one flow line should enter a decision symbol. However, two or three flow lines
may leave the decision symbol
Only one flow line is used with a terminal symbol.
Within standard symbols, write briefly and precisely.
Intersection of flow lines should be avoided.

Fig 1.1 Symbols used in Flow chart

Solving Advantages:
Flowcharts help in communicating the logic of a program in a better way.
The problems can be analyzed effectively with the help of flowchart.
Flowcharts serve as good program documentation.
The flowchart is ablueprint for the programmer to code efficiently.
Flowcharts help in debugging process.

Fig 1.2 Flowchart for adding two numbers


Introduction to Computer Problem Solving Disadvantages:
The flowcharts are complex and clumsy when the program is large or
complicated.
Altering or modifying the flowcharts may require re-drawing completely.
The cost and time taken to draw a flowchart for larger applications are expensive.
Example: Add two numbers
The above flowchart is used for adding two numbers Number1 and [Link]
numbers are the input provided by the user .After adding, the result is stored in the
variable Sum and is printed.
Example: Print odd numbers from 1 to 100
Fig 1.3 Flowchart to Print odd numbers from 1 to 100
The above flowchart is used for printing all odd numbers up to 100. The first value, i
is initialized as zero. A loop is initialized. Starting from i=0, each value is divided by

2 and the remainder is captured .This operation is called modulo of a number. The
modulo of first value is calculated if the result is not equal to zero then the number is
printed and the number is incremented. The i value is checked with the limit, 100.
The numbers are printed until the value is less than the input value.
Example: Find the largest of two numbers
Fig 1.4 Flowchart to find the largest of two numbers

The above flowchart is to find the Largest of two numbers NO1 and [Link]
numbers are the input provided by the user .The number NO1 and NO2 are
compared, If NO1 is larger, the number NO1 is printed or if NO2 is larger, the
number NO2 is printed.
Example: Add two numbers using Function
Fig 1.5a Flowchart of a calling function

Fig 1.5b Flowchart of a Sub function to add two numbers

The flowchart 1.5a is for the calling function. This function is also called as Main
function . The flowchart1.5b is called as the called function which is to add two
numbers a and [Link] numbers are the input provided by the user .After adding the
result is stored in a variable c and it is printed.
Types of Flowcharts
Process Flowchart
Data Flowchart
Business Process Modeling Diagram
Difference between Algorithm, Flowchart and Pseudo code
Algorithm Flowchart Pseudo code
An algorithm is a step by step procedure to solve a [Link] is a graphical
representation of algorithm It is a language representation of algorithm.
User needs knowledge to write [Link] does not need knowledge of program
to draw or understand flowchart User does not need knowledge of program language
to understand or write a pseudo code.
Algorithm Flowchart Pseudo code
An algorithm is a It is a graphical It is a language
step by step representation of representation of
procedure to solve a algorithm algorithm.
problem.
User needs User does not need User does not need
knowledge to write knowledge of program knowledge of program
algorithm. to draw or understand language to understand
flowchart or write a pseudo code.

Algorithmic Problem Solving


For Socio Economic Conditions in Global Perspectives: People today have to strive
hard to maintain
Providing Food for Everybody
Step 1: Start
Step 2: Estimation of people below poverty line.
Step 3: Recommendation about the type and quantity of food from the food
committee
Step 4: Decide the cost
Step 5: Generation of Revenue to meet the food demand
Step 6: Provide food through public distribution system at all levels.
Step 7: Get Feedback from beneficiaries as well as public Step 8: Go to
step 2
Step 9: Stop
Fig 1.6 Flowchart for providing food for Everybody
Process A: The number of people below poverty line in each village is estimated and
the total of people in each district is calculated.
Process B: The food committee will recommend the type of food to be provided and
also the quantity of food.
Process C: From the above inputs, the overall cost is calculated.
Process D: The Finance committee decides how to generate the revenue needed.
Process E: Revenue is generated by implementing Tax, Educational Cess, Import
/Export duties etc.
Process F: The distribution of food is carried out through public distribution system.
Process G: Feedback is provided by the public and beneficiaries which again is an
input to the process to improve the quality of the food provision

Iterations:
A sequence of statements is executed until a specified condition is true is called
iterations.
For loop
While loop
Example: Print n Natural numbers using FOR Loop
Algorithm Pseudo code
Step 1: Start BEGIN
Step 2: Get the value of n. GET n
Step 3: Initialize i=1 INITIALIZE i=1
Step 4: if (i<=n) go to step 5 else go to step 7 FOR (i<=n) DO
Step 5: Print i value and increment i value by 1 PRINT i
Step 6: Go to step 4 i=i+1
Step 7: Stop ENDFOR
END

Example: Print n Natural numbers using WHILE Loop


Algorithm Pseudo code
Step 1: Start BEGIN
Step 2: Get the value of n. GET n
Step 3: Initialize i=1 INITIALIZE i=1
Step 4: if (i<=n) go to step 5 else go to step 7 WHILE(i<=n) DO
Step 5: Print i value and increment i value by 1 PRINT i
Step 6: Go to step 4 i=i+1
Step 7: Stop ENDWHILE
END

Fig 1.8 Flowchart to print n Natural numbers using WHILE Loop


The above flowchart is to print all natural numbers up to n .The user provides the
input value n. The first value, i is initialized as one. A loop is initialized. The i value is
checked with n, the user input. The numbers are printed until the value is less than
the user input value. When the condition becomes false the loop terminates.
Recursion:
A function that calls itself is known as recursion.
Recursion is a process by which a function calls itself repeatedly until some specified
condition has been satisfied.
Example: Factorial
Algorithm Pseudo code
Main Function() Main Function()
Step1: Start BEGIN
Step2: Get n GET n
Step3: call factorial(n) CALL factorial(n)
Step4: print fact PRINT fact
Step5: Stop END

Sub function factorial(n) Sub function factorial(n)


Step1: if(n==1) then fact=1 return fact IF(n==1) THEN
Step2: else fact=n*factorial(n-1) and fact=1 RETURN fact
return fact
ELSE
RETURN fact=n*factorial(n-
1)
Fig 1.9 a) Flowchart of a calling function b) Flowchart of a Sub function to find
factorial of a given number
The flowchart 1.9a is to call the function factorial. This function is called as Main
function or calling function. The flowchart1.5b is called as the called function which is
to find the factorial of the number passed from the main function. The loop exists
until the n value becomes one. Factorial is a recursive function where the function
itself is called again and again.
Difference between Iteration and Recursion
Property Iteration Recursion
Definition A set of instructions
repeatedly executed.
Function calls itself.
Application For loops. For functions.
When the termination
condition for the iterator
Termination Through base case,
ceases to be satisfied.
where there will be
no function call.

Property Iteration Recursion


Used when time Used when code size
complexity needs to needs to be small, and
Usage
be balanced against an time complexity
expanded code size. is not an issue.
Code Size Larger Code Size. Smaller code size
Time Complexity Relatively lower time
complexity
Very high time complexity.

Overview of Object oriented programming approach


Object-oriented programming (OOP) is a method of structuring a program by
bundling related properties and behaviors into individual objects.
Conceptually, objects are like the components of a system. Think of a program as a
factory assembly line of sorts. At each step of the assembly line a system
component processes some material, ultimately transforming raw material into a
finished product.
An object contains data, like the raw or preprocessed materials at each step on an
assembly line, and behavior, like the action each assembly line component performs.
Object-oriented programming is a programming paradigm that provides a means of
structuring programs so that properties and behaviors are bundled into individual
objects.
For instance, an object could represent a person with properties like a name,
age, and address and behaviors such as walking, talking, breathing, and
running. Or it could represent an email with properties like a recipient list,
subject, and body and behaviors like adding attachments and sending.
Put another way, object-oriented programming is an approach for modeling concrete,
real-world things, like cars, as well as relations between things, like companies and
employees, students and teachers, and so on. OOP models real-world entities as
software objects that have some data associated with them and can perform certain
functions.

Another common programming paradigm is procedural programming, which


structures a program like a recipe in that it provides a set of steps, in the form of
functions and code blocks, that flow sequentially in order to complete a task.
The key takeaway is that objects are at the center of object-oriented programming in
Python, not only representing the data, as in procedural programming, but in the
overall structure of the program as well.
Characteristics of object oriented languages

Encapsulation – Encapsulation is capturing data and keeping it safely and securely


from outside interfaces.
One of the common examples of encapsulation is a calculator, as anybody using a calculator
understands its functions, but may not require an understanding of how it works inside.

Inheritance- This is the process by which a class can be derived from a base class
with all features of base class and some of its own. This increases code reusability.
For example, one can create two child classes and name them hatchback and sedan
inherited from the parent class car
Polymorphism- This is the ability to exist in various forms. For example an operator
can be overloaded so as to add two integer numbers and two floats.
A real-life example of polymorphism is a person who at the same time can have
different characteristics. Like a man at the same time is a father, a husband and an
employee. So the same person exhibits different behavior in different situations.
Abstraction- The ability to represent data at a very conceptual level without any
details.
Your car is a great example of abstraction. You can start a car by turning the key or
pressing the start button. You don't need to know how the engine is getting started,
what all components your car has. The car internal implementation and complex
logic is completely hidden from the user.
Classes fundamentals: A Simple Class and Object
Class definitions – Basic building blocks OOP and a single entity which has data and
operations on data together

Objects – The instances of a class which are used in real functionality – its variables
and operations
Create a Class
To create a class, use the keyword class:
Example In python
Create a class named MyClass, with a property named x:
class MyClass:
x=5
Create Object
Now we can use the class named MyClass to create objects:
Example In python
Create an object named p1, and print the value of x:
p1 = MyClass()
print(p1.x)

Accessing members of class,

Example In python
Insert a function that prints a greeting, and execute it on the p1 object:

class Person:
def __init__(self, name, age):
[Link] = name
[Link] = age

def myfunc(self):
print("Hello my name is " + [Link])
p1 = Person("John", 36)
[Link]()

Initialization of class objects:(Constructor, Destructor).

Sample #python Program


def __init__(self):

self.str1 = ‘PrepInsta’

print(‘Object Created’ , self.str1)

def __del__(self):

print(‘DEstructor is called Manually’)

ob = A()

del ob

#ob1=A()

#destructor will be called automattically for ob1


OUTPUT FOR THE ABOVE PROGRAM
Object Created PrepInsta
DEstructor is called Manually

End of Unit I

UNIT II
Introduction

What is Python?
Python is a popular programming language. It was created by Guido van Rossum,
and released in 1991.
It is used for:
 web development (server-side),
 software development,
 mathematics,
 system scripting.
What can Python do?
PYTHON
 can be used on a server to create web applications.
 can be used alongside software to create workflows.
 can connect to database systems. It can also read and modify files.
 can be used to handle big data and perform complex mathematics.
 can be used for rapid prototyping, or for production-ready software
development.
Why Python?
 works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
 has a simple syntax similar to the English language.
 has syntax that allows developers to write programs with fewer lines than
some other programming languages.
 runs on an interpreter system, meaning that code can be executed as soon as
it is written. This means that prototyping can be very quick.
 can be treated in a procedural way, an object-oriented way or a functional
way.
Python Syntax compared to other programming languages
 Python was designed for readability, and has some similarities to the English
language with influence from mathematics.
 Python uses new lines to complete a command, as opposed to other
programming languages which often use semicolons or parentheses.
 Python relies on indentation, using whitespace, to define scope; such as the
scope of loops, functions and classes. Other programming languages often
use curly-brackets for this purpose.

Python interpreter
Python is an interpreted, high-level, general-purpose programming language.

Interpreted Languages
When you write a program in C/C++, you have to compile it. Compilation involves
translating your human understandable code to machine understandable code, or
Machine Code. Machine code is the base level form of instructions that can be
directly executed by the CPU. Upon successful compilation, your code generates an
executable file. Executing this file runs the operations in your code step by step.
For the most part, Python is an interpreted language and not a compiled one,
although compilation is a step. Python code, written in .py file is first compiled to
what is called bytecode (discussed in detail further) which is stored with a .pyc or
.pyo format.
Instead of translating source code to machine code like C++, Python code it
translated to bytecode. This bytecode is a low-level set of instructions that can be
executed by an interpreter. In most PCs, Python interpreter is installed at
/usr/local/bin/python3.8. Instead of executing the instructions on CPU, bytecode
instructions are executed on a Virtual Machine.

Why Interpreted?
One popular advantage of interpreted languages is that they are platform-
independent. As long as the Python bytecode and the Virtual Machine have the
same version, Python bytecode can be executed on any platform (Windows, MacOS,
etc).

Dynamic typing is another advantage. In static-typed languages like C++, you have
to declare the variable type and any discrepancy like adding a string and an integer
is checked during compile time. In strongly typed languages like Python, it is the job
of the interpreter to check the validity of the variable types and operations performed.

Disadvantages of Interpreted languages


Dynamic typing provides a lot of freedom, but simultaneously it makes your code
risky and sometimes difficult to debug.
Python is often accused of being ‘slow’. Now while the term is relative and argued a
lot, the reason for being slow is because the interpreter has to do extra work to have
the bytecode instruction translated into a form that can be executed on the machine.
If you can talk in your native language to someone, that would generally work faster
than having an interpreter having to translate your language into some other
language for the listener to understand.

Interactive and script mode


Interactive Mode
Interactive mode, also known as the REPL provides us with a quick way of running
blocks or a single line of Python code. The code executes via the Python shell, which
comes with Python installation. Interactive mode is handy when you just want to
execute basic Python commands or you are new to Python programming and just
want to get your hands dirty with this beautiful language.

To access the Python shell, open the terminal of your operating system and then
type "python". Press the enter key and the Python shell will appear. This is the same
Python executable you use to execute scripts, which comes installed by default on
Mac and Unix-based operating systems.
C:\Windows\system32>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> indicates that the Python shell is ready to execute and send your
commands to the Python interpreter. The result is immediately displayed on the
Python shell as soon as the Python interpreter interprets the command.

To run your Python statements, just type them and hit the enter key. You will get the
results immediately, unlike in script mode. For example, to print the text "Hello
World", we can type the following:

>>> print("Hello World")


Hello World
>>>

Script Mode
If you need to write a long piece of Python code or your Python script spans multiple
files, interactive mode is not recommended. Script mode is the way to go in such
cases. In script mode, You write your code in a text file then save it with a .py
extension which stands for "Python". Note that you can use any text editor for this,
including Sublime, Atom, notepad++, etc.
If you are in the standard Python shell, you can click "File" then choose "New" or
simply hit "Ctrl + N" on your keyboard to open a blank script in which you can write
your code. You can then press "Ctrl + S" to save it.
After writing your code, you can run it by clicking "Run" then "Run Module" or simply
press F5.
Let us create a new file from the Python shell and give it the name "[Link]". We
need to run the "Hello World" program. Add the following code to the file:
print("Hello World")
Click "Run" then choose "Run Module". This will run the program:
Output
Hello World
values and types, operators, expressions, statements, precedence of
operators, Multiple assignments, comments.

Values
Variables are nothing but reserved memory locations to store values. This means
that when you create a variable you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and decides
what can be stored in the reserved memory. Therefore, by assigning different data
types to variables, you can store integers, decimals or characters in these variables.
Assigning Values to Variables
Python variables do not need explicit declaration to reserve memory space. The
declaration happens automatically when you assign a value to a variable. The equal
sign (=) is used to assign values to variables.
The operand to the left of the = operator is the name of the variable and the operand
to the right of the = operator is the value stored in the variable. For example −
counter = 100 # An integer assignment
miles = 1000.0 # A floating point
name = "John" # A string

print counter
print miles
print name
Here, 100, 1000.0 and "John" are the values assigned to counter, miles, and name
variables, respectively. This produces the following result −
100
1000.0
John
Multiple Assignment
Python allows you to assign a single value to several variables simultaneously. For
example −
a=b=c=1
Here, an integer object is created with the value 1, and all three variables are
assigned to the same memory location. You can also assign multiple objects to
multiple variables. For example −
a,b,c = 1,2,"john"
Here, two integer objects with values 1 and 2 are assigned to variables a and b
respectively, and one string object with the value "john" is assigned to the variable c.

DATA TYPES

Variables can store data of different types, and different types can do
different things.

Python has the following data types built-in by default, in these categories:

Text Type: str

Numeric Types: int, float, complex


Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set, frozenset

Boolean Type: bool

Binary Types: bytes, bytearray, memoryview

None Type: NoneType

Operators
 Indentation matters to code meaning
• Block structure indicated by indentation
 First assignment to a variable creates it
• Variable types don’t need to be declared.
• Python figures out the variable types on its own.
 Assignment is = and comparison is ==
 For numbers + - * / % are as expected
• Special use of + for string concatenation and % for string formatting (as
in C’s printf)
 Logical operators are words (and, or, not) not symbols
 The basic printing command is print
 Integers (default for numbers)
z = 5 / 2 # Answer 2, integer division
 Floats
x = 3.456
 Strings
• Can use “” or ‘’ to specify with “abc” == ‘abc’
• Unmatched can occur within the string: “matt’s”
• Use triple double-quotes for multi-line strings or strings than contain
both ‘ and “ inside of them:
“““a‘b“c”””
o Whitespace is meaningful in Python: especially indentation and placement of
newlines
o Use a newline to end a line of code
 Use \ when must go to next line prematurely
o No braces {} to mark blocks of code, use consistent indentation instead
 First line with less indentation is outside of the block
 First line with more indentation starts a nested block
o Colons start of a new block in many constructs, e.g. function definitions, then
clauses
o Start comments with #, rest of line is ignored

NAMING RULES
 Names are case sensitive and cannot start with a number. They can contain
letters, numbers, and underscores.
bob Bob _bob _2_bob_ bob_2 BoB
 There are some reserved words:
and, assert, break, class, continue, def, del, elif, else, except, exec, finally, for,
from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try,
while
The Python community has these recommend-ed naming conventions
 joined_lower for functions, methods and, attributes
 joined_lower or ALL_CAPS for constants
 StudlyCaps for classes
 camelCase only to conform to pre-existing conventions
 Attributes: interface, _internal, __private

You might also like