
Why learn Python?
Hi, you landed on this course because you want to learn python. Just so we are clear, this
is a CRASH COURSE for python where you will be learning basics of python and how
to plot graphs with data sets available for you.
Python is one of the most loved programming languages by developers, data scientists,
software engineers, and even hackers because of its versatility, flexibility, and
object-oriented features.
You will be amazed to know that all top tech giants are using python for example:
YouTube
Spotify
Netflix
Uber
Dropbox
The entry-level Python developer salary in the US is $78,000 a year on average,
The average junior Python developer salary is $90,000,
The mid-level Python developer salary reaches $110,000,
While the senior Python developer earns $120,000 on average.
Finally professional like Analysts, Executives or even Marketing Giant who wants to
generate insights from data sets to make informed decisions can benefit from this crash
course.
So how does the course look like?
Well, we will start by simply installing python on your machine. We will cover Mac and
Windows platforms.
Then we will learn all the basics, logics, conditions, object and functions.
I don't want you to spend hours and hours just learning. I want you to learn fast and
start implementing instantly. Hence we will be plotting some interesting graphs with real-world data with the help of some of the most popular python libraries.
So What you waiting for enrol today and I will see you inside the course.
Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple. If you wish, you are invited to install the most recent version of Python from the Python website (https://www.python.org). A current “universal binary” build of Python, which runs natively on the Mac's new Intel and legacy PPC CPU's, is available there.
Unlike most Unix systems and services, Windows does not include a system supported the installation of Python. To make Python available, the CPython team has compiled Windows installers (MSI packages) with every release for many years. These installers are primarily intended to add a per-user installation of Python, with the core interpreter and library being used by a single user. The installer is also able to install for all users of a single machine, and a separate ZIP file is available for application-local distributions.
Python is completely object-oriented, and not "statically typed". You do not need to declare variables before using them or declare their type. Every variable in Python is an object.
Python supports two types of numbers - integers and floating-point numbers. (It also supports complex numbers, which will not be explained in this tutorial).
Python supports integers, floating-point numbers and complex numbers. They are defined as int , float and complex class in Python. Integers and floating points are separated by the presence or absence of a decimal point. 5 is integer whereas 5.0 is a floating-point number.
There are three numeric types in Python:
int
float
complex
You can convert from one type to another with the int(), float(), and complex() methods:
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x)
#convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
String literals in python are surrounded by either single quotation marks or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
print("Hello")
print('Hello')
Assigning a string to a variable is done with the variable name followed by an equal sign and the string:
a = "Hello"
print(a)
Python user input from the keyboard can be read using the input() built-in function. The input from the user is read as a string and can be assigned to a variable. After entering the value from the keyboard, we have to press the “Enter” button. Then the input() function reads the value entered by the user.
Python executes code top to bottom, when written in the correct syntax. To execute the code in our python tutorials, you will need to install python in your machine as a prerequisite. A small description on how to install Python and get the interpreter running is given here. Once the interpreter is running you can start typing in commands to get the result.
Python offers a range of compound datatypes often referred to as sequences. List is one of the most frequently used and very versatile datatype used in Python.
In Python programming, a list is created by placing all the items (elements) inside a square bracket [ ], separated by commas.
It can have any number of items and they may be of different types (integer, float, string etc.).
How to access elements from a list?
There are various ways in which we can access the elements of a list.
List Index
We can use the index operator [] to access an item in a list. Index starts from 0. So, a list having 5 elements will have index from 0 to 4.
Trying to access an element other that this will raise an IndexError. The index must be an integer. We can't use float or other types, this will result into TypeError.
Nested list are accessed using nested indexing.
A tuple lets us “chunk” together related information and use it as a single thing. Tuples support the same sequence operations as strings. The index operator selects an element from a tuple. So like strings, tuples are immutable.
We saw earlier that we could group together pairs of values by surrounding with parentheses. Recall this example:
>>> year_born = ("Paris Hilton", 1981)
This is an example of a data structure — a mechanism for grouping and organizing data to make it easier to use.
The pair is an example of a tuple. Generalizing this, a tuple can be used to group any number of items into a single compound value. Syntactically, a tuple is a comma-separated sequence of values. Although it is not necessary, it is conventional to enclose tuples in parentheses:
>>> julia = ("Julia", "Roberts", 1967, "Duplicity", 2009, "Actress", "Atlanta, Georgia")
Tuples are useful for representing what other languages often call records — some related information that belongs together, like your student record. There is no description of what each of these fields means, but we can guess. A tuple lets us “chunk” together related information and use it as a single thing.
Tuples support the same sequence operations as strings. The index operator selects an element from a tuple.
>>> julia[2]
1967
But if we try to use item assignment to modify one of the elements of the tuple, we get an error:
>>> julia[0] = "X"
TypeError: 'tuple' object does not support item assignment
So like strings, tuples are immutable. Once Python has created a tuple in memory, it cannot be changed.
Of course, even if we can’t modify the elements of a tuple, we can always make the julia variable reference a new tuple holding different information. To construct the new tuple, it is convenient that we can slice parts of the old tuple and join up the bits to make the new tuple. So if julia has a new recent film, we could change her variable to reference a new tuple that used some information from the old one:
>>> julia = julia[:3] + ("Eat Pray Love", 2010) + julia[5:]
>>> julia
("Julia", "Roberts", 1967, "Eat Pray Love", 2010, "Actress", "Atlanta, Georgia")
Functions are an essential part of the Python programming language: you might have already encountered and used some of the many fantastic functions that are built-in in the Python language or that come with its library ecosystem. However, as a Data Scientist, you’ll constantly need to write your own functions to solve problems that your data poses to you.
You use functions in programming to bundle a set of instructions that you want to use repeatedly or that, because of their complexity, are better self-contained in a sub-program and called when needed. That means that a function is a piece of code written to carry out a specified task. To carry out that specific task, the function might or might not need multiple inputs. When the task is carried out, the function can or can not return one or more values.
There are three types of functions in Python:
Built-in functions, such as help() to ask for help, min() to get the minimum value, print() to print an object to the terminal,… You can find an overview with more of these functions (https://docs.python.org/3/library/functions.html).
User-Defined Functions (UDFs), which are functions that users create to help them out; And
Anonymous functions, which are also called lambda functions because they are not declared with the standard "def" keyword.
A return statement is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned.
return: it can be situated anywhere in the function body. A return statement ends the execution of the function call and "returns" the result, i.e. the value of the expression following the return keyword, to the caller. If the return statement is without expression, the special value None is returned.
Conditions. Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Conditional statements are part of every programming language. With conditional statements, we can have code that sometimes runs and at other times does not run, depending on the conditions of the program at that time.
When we fully execute each statement of a program, moving from the top to the bottom with each line executed in order, we are not asking the program to evaluate specific conditions. By using conditional statements, programs can determine whether certain conditions are being met and then be told what to do next.
Let’s look at some examples where we would use conditional statements:
If the student receives over 65% on her test, report that her grade passes; if not, report that her grade fails
If he has money in his account, calculate interest; if he doesn’t, charge a penalty fee
If they buy 10 oranges or more, calculate a discount of 5%; if they buy fewer, then don’t
Through evaluating conditions and assigning code to run based on whether or not those conditions are met, we are writing conditional code.
Python programming language provides following types of loops to handle looping requirements. Python provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition checking time.
While Loop:
In python, while loop is used to execute a block of statements repeatedly until a given a condition is satisfied. And when the condition becomes false, the line immediately after the loop in program is executed.
Syntax :
while expression:
statement(s)
for in Loop: For loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there is no C style for loop, i.e., for (i=0; i<n; i++). There is “for in” loop which is similar to for each loop in other languages. Let us learn how to use for in loop for sequential traversals.
Syntax:
for iterator_var in sequence:
statements(s)
Multiplication in Python is fairly simple and easy to do. But what about using exponents? How would you raise a number to the second power, for example? If you're not sure, you'll probably find the answer pretty straightforward.
To raise a number to the power of another number, you need to use the "**" operator. Where multiplying two numbers only uses one * symbol, the operator for raising one number to the power of another uses two: **
I would like you to do an exercise yourself by figuring out how the exponent function works. Please go to the next lesson and see what you need to do.
Whether you want to:
Build the skills you need to get your first Python programming job
Move to a more senior software developer position
Get started with Machine Learning, Data Science, Django or other hot areas that Python specialises in
Learn Python to be able to create your own Python apps quickly.
Will I be able to learn Python and find a job after completing this course?
I have heard of quite a few success stories where students have rigorously followed the course and have found a job afterwards. However, whether you will be able to learn Python and be job-ready, heavily depends on you.
This course is aimed at complete beginners who have never programmed before, as well as existing programmers who want to increase their career options by learning Python.
How much time will I need to complete the course?
That depends on two factors:
(1) Your background: Someone coming from a math or computer science background may be able to complete the course in a shorter time compared to someone coming from a social science background for example.
(2) The effort you put in: If you just watch the videos, you may finish the course in two days. However, simply watching the videos is not enough. You need to experiment with the code you see in the videos. The more you experiment with it the better you become.
Depending on the two factors I mentioned above, students spend from one week to three months to complete the course, most spending one month.
I don't know anything about programming. Will I still be able to learn Python?
This course assumes you have no previous knowledge of programming. Whenever a programming term is mentioned (e.g. a variable) the meaning of the term is explained thoroughly so you not only understand how to use that particular term in Python, you also understand what that term means in programming.
Will I get support if I get stuck?
Yes. Feel free to drop a question in the Q&A, and me, or my teaching assistant, will answer your questions within the same day.
Does this course cover Python 2 or Python 3?
Python 3