Python Programming Knowledge

Nikhil Upadhyay
Knowledge Gurukul
Published in
9 min readMar 3, 2021

All About Python from zero to infinity.

Welcome all of you on Knowledge Gurukul here we are going to discuss about Python.

Before you are able to start using Python to take over your programming needs, it is important to start learning more about it and all of the great benefits you will receive when using this program. Python is a high level programming tool, which means that it is easy to use and read, even as a beginner. Compared to using other popular codes, like Java and C++, this can make Python much easier to complete.

Benefits of Python In real time Environment :

  1. An elegant syntax which will make the programs so easy to read.
    Language that is easy to use so that the program will work without a lot
    of bugs.
  2. Has a large library that will work with other programming tasks such as
    changing files, searching for text, and connecting with web servers.
  3. Python programming can be run on any unit including Unix, Linux,
    Windows, and Mac OS X.
  4. Easy to use and read.
  5. Uses English as the main language.
  6. Already present on some computers.
  7. Can work with other programming languages

Origins of Python :

The beginning of the modern Python programming started in December of
1989. The creator of this program was Guido van Ross-um who began
programming as more of a hobby. Python has currently 2 versions

  1. Python 2
  2. Python 3

Python 2.0 was released during 2000 to make it more community
oriented and to have a transparent development process. There are a few newer versions of Python 2.0 still being used, but Python 3 has been taking the world by storm and most anticipate this will be the normal one used within the next few years.

Python 3

This version of Python was released in 2008. It is not simply an update to the
program, but a complete change in it. While there are a lot of great features that come with this version, it doesn’t have a backward compatibility so you will have to make a choice between Python 2.0 and Python 3

In Simply way there a library called as future is can be use to convert python version from Python 2 to Python 3.

Python is an object-oriented programming language created by Guido Ross um in 1989. It is ideally designed for rapid prototyping of complex applications. It has interfaces to many OS system calls and libraries and is extensible to C or C++. Many large companies use the Python programming language include NASA, Google, YouTube, BitTorrent, etc.

Python language can use for multiple platforms for web and app development as well as for Data or in Machine Learning, AI. Python is in demand after 2017. Now a days all organisation in world switch to Python or start new projects on Python.

Interpreter: An interpreter is a program which also converts a high-level programming language (like Python, PHP, Perl) into machine code. … Contrary to a compiler, it converts source code to machine code when the program is running and not before the program runs.

Windows: There are many interpreters available freely to run Python scripts like IDLE (Integrated Development Environment) that comes bundled with the Python software downloaded from http://python.org/.

Linux: Python comes preinstalled with popular Linux such as Ubuntu and Fedora. To check which version of Python you’re running, type “python” in the terminal emulator. The interpreter should start and print the version number.

mac OS: Generally, Python 2.7 comes bundled with mac OS. You’ll have to manually install Python 3 from http://python.org/.

Now Move towards Python and understand python.

Python Basic :

  1. Python Keyword
  2. Python Data Type
  3. Python Data Structure
  4. Control Flow: Conditional statement
  5. Looping (For/While), iterator
  6. Indentation and Comment in Python
  7. User input In Python
  8. Variable in Python
  9. Operators
  10. Function in Python (def, lambda etc.)
  11. Class and object in Python
  12. OOPS (Object-oriented programming System )
  13. Pre Define functions (map(), filter(),get() etc)
  14. Pre Define Methods in Python
  15. Exception handling

Basically to work with Python initially we have to understand this 1 to 15 basic concept in Python. So, Lets start with Python Keyword.

1. Python Keyword :

Python has a set of keywords or set of words that are reserved. We can’t use this words as variable names or any function name this keyword have different role in Python. let’s discuss about all keywords in Python.

  1. keyword[ and ] — A logical operator
  2. keyword[ as ] — To create an alias
  3. keyword[ assert] — for debugging
  4. keyword[ break ] — to break a loop
  5. keyword[ class ] — To define a class
  6. keyword[ continue ] — To continue to the next iteration of a loop
  7. keyword[ def] — To define a function
  8. keyword[ del ] — To delete an object
  9. keyword[ elif ] — Used in conditional statements, same as else if
  10. keyword[ else ] — Used in conditional statements
  11. keyword[ except] — Used with exceptions, what to do when an exception occurs
  12. keyword[ False ] — Boolean value, result of comparison operations
  13. keyword[ finally] — Used with exceptions, a block of code that will be executed no matter if there is an exception or not
  14. keyword[ for ] — To create a for loop
  15. keyword[ from ] — To import specific parts of a module
  16. keyword[ global] — To declare a global variable
  17. keyword[ if] — To make a conditional statement
  18. keyword[ import ] — To import a module
  19. keyword[ in] — To check if a value is present in a list, tuple, etc.
  20. keyword[ is ] — To test if two variables are equal
  21. keyword[ lambda ] — To create an anonymous function
  22. keyword[ None] — Represents a null value
  23. keyword[ nonlocal ] — To declare a non-local variable
  24. keyword[ not ] — A logical operator
  25. keyword[ or] — A logical operator
  26. keyword[ pass ] — A null statement, a statement that will do nothing
  27. keyword[ raise ] — To raise an exception
  28. keyword[ return ] — To exit a function and return a value
  29. keyword[ True ] — Boolean value, result of comparison operations
  30. keyword[ try] — To make a try except statement
  31. keyword[ while ] — To create a while loop
  32. keyword[ with ] — Used to simplify exception handling
  33. keyword[ yield ] — To end a function, returns a generator

Basically this are the keywords in Python and we will use this keyword in our programs to understand there uses in Python.

2. Python Data Type :

  1. String [str] for string
  2. int, float, complex [for number]
  3. Sequence Types: list, tuple, range
  4. Mapping Type: dict [dictionary]
  5. Set Types: set
  6. Boolean Type: bool [True, False]
  7. Binary Types: byte

String in Python :

Numeric Data type[int, float, complex] :

Sequence Types: list, tuple, range

  1. List :

Lists are used to store multiple items in a single variable.Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage. Lists are created using square brackets:

2. Tuple :

A tuple is a sequence of immutable Python objects. Tuples are just like lists with the exception that tuples cannot be changed once declared. Tuples are usually faster than lists.

Range :

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.

Syntax of range — range(start, stop, step)

Mapping Type: dict [dictionary] :

Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered*, changeable and does not allow duplicates.

Here is the link of git repository of python Data Type :

Python Data Structure :

  • list: Mutable Dynamic Arrays.
  • tuple: Immutable Containers.
  • array.array: Basic Typed Arrays.
  • str: Immutable Arrays of Unicode Characters.
  • bytes: Immutable Arrays of Single Bytes.
  • byte array: Mutable Arrays of Single Bytes.

In this Repository discuss about Python Data Structure.

3. Control Flow — Conditional statement :

In programming language Control flow statement is use for flow the code as well as apply condition on them to takeout output according to required output. for better understand see the Block if condition is satisfy then inside the condition code is going to run otherwise it will send you outside from the condition.

Type :

  • Simple if
  • if-else
  • nested if
  • if-elif-else

Simple if :

If statements are control flow statements that help us to run a particular code, but only when a certain condition is met or satisfied. A simple if only has one condition to check.

Simple if

if-else :

The if-else statement evaluates the condition and will execute the body of IF if the test condition is True, but if the condition is False, then the body of ELSE is executed.

if else

Nested if:

Nested if statements are an if statement inside another if statement.

Nested If Working

if-elif-else:

The if-elif-else statement is used to conditionally execute a statement or a block of statements.

Now briefly understand about Conditional Statement lets try some code on this. here is the git repository link where you can see how to implement this conditional statements.

Logical Conditions :

  • Equals: a == b
  • Not Equals: a != b
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b

5. Looping (For/While), iterator :

In Python, we generally have two loops/repetitive statements:

  • for loop
  • while loop

A repetition statement is used to repeat a group(block) of programming instructions.

for loop:

A for loop is used to iterate over a sequence that is either a list, tuple, dictionary, or a set. We can execute a set of statements once for each item in a list, tuple, or dictionary.

for example you are owner of company and you want to give 2000 as Diwali bonus to every employee of your company and you have to update this transaction in your database then in this condition you can use a for loop condition to automatically update the bonus in Database via apply condition on for loop.

In Python various functions are added for [FOR loop] via this function use for loop is more easy, functions like range, nrange, random etc.

while loop:

In Python, while loops are used to execute a block of statements repeatedly until a given condition is satisfied. Then, the expression is checked again and, if it is still true, the body is executed again. This continues until the expression becomes false.

Indentation and Comment in Python :

Python indentation is used to define a block of statement under a body of function or loop or decision structure etc. In other languages such as Java, C, C++ braces {} were used to define a block of statement. The body of function or loop is started from a colon. Usually four white spaces are used for indentation. and for better understand indentation we can say that a person wants to go from roof to ground then he have to take stairs as like that indentation is work for go one line to another line and make sure we are going to correct direction.

Comment :

Basically in python A comment Section is come to use to pass a comment or suppose you write a code and you want to describe or give a Symbol to the code via you can easily understand or find the code and why it is written for that we use comment in Python and in Python comment will define in

[#, ##, ###, “ ”].

2. User input In Python :

user input in python is come in use when you want a user give some command and according to user command or input program will give output according to program.

--

--

Nikhil Upadhyay
Knowledge Gurukul

Experience in AI(Computer Vision), Machine Learning, Python, Data Science and Proficient in Data Analysis, Predictive modelling, NLP, Database(SQL,