
My specialization teaches the fundamentals of programming in Python 3. We will begin at the beginning, with variables, conditionals, and loops, and get to some intermediate material like keyword parameters, list comprehensions, lambda expressions, and class inheritance.
You will have lots of opportunities to practice. You will also learn ways to reason about program execution, so that it is no longer mysterious and you are able to debug programs when they don’t work.
By the end of the specialization, you’ll be writing programs that query Internet APIs for data and extract useful information from them. And you’ll be able to learn to use new modules and APIs on your own by reading the documentation. That will give you a great launch toward being an independent Python programmer.
But it is also appropriate as a first set of courses in Python if you are already familiar with some other programming language, or if you are up for the challenge of diving in head-first.
Visit the link https://www.python.org/downloads/ to download the latest release of Python. In this process, we will install Python 3.6.7 on our Windows operating system.
Double-click the executable file which is downloaded, select customize installation and proceed.
The following window shows all the optional features. All the features need to be installed and are checked by default, we need to click next to continue.
The following window shows a list of advanced options. Check all the options which you want to install and click next. Here, we must notice that the first check-box (install for all users) must be checked.
Now we are ready to install python-3.6.7 Lets install it.
Now try to run python on the command prompt. Type the command python in case of python2 or python3 in case of pyton3. It will show an error as given in the below image. It is because we haven’t set the path.
To set the path of python, we need to right click on “My Computer” and go to properties è Advance è Environment Variables.
Add the new path variable in the user variable section.
Type PATH as the variable name and set the path to the installation directory of the python shown in the below image.
Now, the path is set, we are ready to run python on our local system. Restart CMD and type python again. It will open the python interpreter shell where we can execute the python statements.
Python Variables
Variable is a name which is used to refer memory location. Variable also know as identifier and used to hold value. In Python, we don’t need to specify the type of variable because Python is a type infer language and smart enough to get variable type.
Variables names can be a group of both letters and digits, but they have to begin with a letter or an underscore.
It is recommended to use lowercase letters for variable name. Rahul and rahul both are two different variables.
Identifier Naming
Variables are the example of identifiers. An Identifier is used to identify the literals used in the program. The rules to name an identifier are given below.
· The first character of the variable must be an alphabet or underscore ( _ ).
· All the characters except the first character may be an alphabet of lower-case(a-z), upper-case(A-Z), underscore or digit (0-9).
· Identifier name must not contain any white-space, or special characters (!, @, #, %, ^, &, *)
· Identifier name must not be similar to any keyword defined in the language.
· Identifier names are case sensitive for example my name and MyName is not the same.
· Example of valid identifiers: a123 or _n or n_9 etc.
· Examples of invalid identifiers: 1a, n%4,n 9 etc
Declaring Variable and Assigning Values
Python does not bound us to declare variable before using in the application. It allows us to create variable at required time. We don’t need to declare explicitly variable in Python. When we assign any value to the variable that variable is declared automatically.
The equal ( - ) operator is used to assign value to a variable.
Python Literals
Literals can be defined as a data that is given in a variable or constant.
Python supports
1. String literals
a. Adding back slash at the end of each line
b. Using triple quotation marks.
2. Numeric Literals
3. Boolean Literals
4. Special Literals
5. Literal Collections
Python Operators
The operator can be defined as a symbol which is responsible for a particular operation between two operands. Operators are the pillars of a program on which the logic is built in a particular programming language. Python provides a variety of operators described as follows.
o Arithmetic operators
o Comparison operators
o Assignment operators
o Logical operators
o Bitwise operators
o Membership operators
o Identity operators
Python supports the usual logical conditions from mathematics:
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
These conditions can be used in several ways, most commonly in "if statements" and loops.
An "if statement" is written by using the if keyword.
Example 1: (If statement)
a = 33
b = 200
if b > a:
print("b is greater than a")
Output:
b is greater than a
Why we use loops in python?
The looping simplifies the complex problems into the easy ones. It enables us to alter the flow of the program so that instead of writing the same code again and again, we can repeat the same code for a finite number of times. For example, if we need to print the first 10 natural numbers then, instead of using the print statement 10 times, we can print inside a loop which runs up to 10 iterations.
Advantages of loops
The following advantages of loops in Python.
It provides code re-usability.
Using loops, we do not need to write the same code again and again.
Using loops, we can traverse over the elements of data structures (array or linked lists).
The python while loop allows a part of the code to be executed until the given condition returns false. It is also known as a pre-tested loop.
It can be viewed as a repeating if statement. When we don’t know the number of iterations then the while loop is most effective to use.
The syntax is:
While expression:
Statements
Here, the statements can be a single statement or a group of statements. The expression should be any valid python expression resulting in true or false. The true is any non-zero value and false is 0.
The break is a keyword in python which is used to bring the program control out of the loop. The break statement breaks the loops one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. In other words, we can say that break is used to abort the current execution of the program and the control goes to the next line after the loop.
The break is commonly used in the cases where we need to break the loop for a given condition.
The syntax of the break is:
#loop statements
Break;
Example:
list =[1,2,3,4]
count = 1;
for i in list:
if i == 4:
print("item matched")
count = count + 1;
break
print("found at",count,"location");
Example 2
str = "python"
for i in str:
if i == 'o':
break
print(i);
The continue statement in Python is used to bring the program control to the beginning of the loop. The continue statement skips the remaining lines of code inside the loop and start with the next iteration. It is mainly used for a particular condition inside the loop so that we can skip some specific code for a particular condition. The continue statement in python is used to bring the program control to the beginning of the loop. The continue statement skips the remaining lines of code inside the loop and start with the next iteration. It is mainly used for a particular condition inside the loop so that we can skip some specific code for a particular condition.
Syntax for continue statement
# loop statements
Continue
# the code to be skipped
In this course, you'll learn the fundamentals of the Python programming language, along with programming best practices. You’ll learn to represent and store data using Python data types and variables, and use conditionals and loops to control the flow of your programs. You’ll harness the power of complex data structures like lists, sets, dictionaries, and tuples to store collections of related data. You’ll define and document your own custom functions, write scripts, and handle errors. Lastly, you’ll learn to find and use modules in the Python Standard Library and other third-party libraries.
In this training program I will be covering all the domains and the concepts involved under the umbrella of artificial intelligence, and I will also be showing you a couple of use cases and practical implementations by using Python. So there’s a lot to cover in the training program.
Python is a general purpose, dynamic, high-level and interpreted programming language. It supports Object Oriented programming approach to develop applications. IT is simple and easy to learn and provides lots of high-level data structures.
Python is easy to learn yet powerful and versatile scripting language, which makes it attractive for Application Development.
Python’s syntax and dynamic typing with its interpreted nature make it an ideal language for scripting and rapid application development.