Python- Zero to Hero

Shivendra Singh
6 min readJun 19, 2019

Python comprehensive guide for beginners

Python is interpreted, interactive, object-oriented, and widely used computer programming language. After reading this article you will have an understanding of how things work in python.

Trust me, it’s very easy to learn,read and implement !

  • Python Installation
  • Python - Hello World
  • Assigning Values to Variables
  • Python Strings
  • Python Lists
  • Python Tuples
  • Python Dictionary
  • Python Operator & Data Type conversion
  • User Input
  • Python Decision Making & Loops
  • Python Functions

Python Installation

You can install python from their official site https://www.python.org/downloads/

I personally use Spyder, it is a powerful scientific environment written in Python, for Python, and designed by and for scientists, engineers and data analysts.

If you want to use Spyder, then install it with Anaconda. Anaconda is open-source and it is the easiest way to perform Python/R data science and machine learning on Linux, Windows, and Mac OS.

https://www.anaconda.com/distribution/

Python — Hello World !

Print (“Whatever you want to print”)

Printing something using variables.

Assigning Values to Variables

Python has 5 standard data types- String, Numbers, List, Tuple and Dictionary.

In below screenshot, we have stored data that could be of many types. Like age is float and address could be alphanumeric characters.

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.

Python Strings

Set of characters within a quotation mark is called a string.

  • Created a String, len(string) will give us the length of string all characters of the string.
  • string [0:7], will print Learning because indexes start from 0 and it’s printing till 7.
  • string.lower() and string.upper() will convert it to lower and upper case.

Python Lists

Lists are used to store multiple data at the same time, it contains items separated by commas and enclosed within square brackets ([]).

Values stored in a list can be accessed using their index values.

  • Creation of list
  • Printing list with indexes
  • Looping within list
  • Adding/Removing something within a list.
  • The plus (+) sign is the list concatenation operator and we can merge multiple lists using the + operator.

Python Tuples

A tuple is also similar to a list, it consists of values separated by commas and enclosed within parentheses().

Tuples can be considered as a read-only list, item in a tuple can’t be modified.

Python Dictionary

We use {} curly brackets to construct the dictionary, and [] square brackets to index it. Separate the key and value with colons: and with commas, between each pair.

Dictionaries are unordered, so the order that the keys are added doesn’t necessarily reflect what order they may be reported back.

Python Operators & Data Type Conversion

  • Arithmetic operators are used with numeric values to perform common mathematical operations.
  • Type conversion, float(x) will convert interger x into float.

User Input

Your programs can prompt the user for input. All input is stored as a string.

Python Decision Making and Loops

Decision making is the anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions.

When we use if else or other condition we need to determine which action to take and which statements to execute if the outcome is TRUE or FALSE otherwise.

If statement

  • Simple if statement, checking about 2 numbers. Indentation is important.
  • Indentation is highlighted in yellow, whitespace after if statement, otherwise it will produce error.

Elif statement

Input & Output

Elif is ways of checking conditions “if the previous conditions were not true, then try this condition”.

Else

  • The if ..else statement evaluates test expression and will execute the body of if. only when the test condition is True.
  • If the condition is False, the body of Else is executed. Indentation is used to separate the blocks.

Loops- For Loop

For loop in Python is used to iterate over a sequence (list, tuple, strings and dictionary)or other iterable objects. Iterating over a sequence is called traversal.

  • Here, val is the variable that takes the value of the item inside the sequence on each iteration.
  • Loop continues until we reach the last item in the sequence. The body of for loop is separated from the rest of the code using indentation.
  • We can also use break, continue statement along with for loops and if else statement according to your need.

While Loops

The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.

In while loop expression is checked first, if executes the code only if expression is correct. After one iteration it checks again if is true then execution takes place, it will iterate until it is false.

  • We took input from user, that is 3.
  • The test expression will be true as long as our counter variable i is less than or equal to n that 3.
  • Don’t forget to increase the value of i.
  • You can combine while loops with other conditions else, if and more.

Python Function

A function is a group of related statements that perform a specific task. A function is a block of organized, reusable code that is used to perform a single, related action.

Data which we pass to the function is known as parameters.

A function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).

There are different type of arguments used in function like required, keyword, default and variable-length argument.

Learning how to program or getting started with a new language isn’t easy, this is what others say. But it is really very easy, It has simple easy-to-use syntax, making it the perfect language for someone trying to learn computer programming for the first time.

It is a comprehensive guide where I discussed basics of python and one can get started in Python.

If you want to learn basics of Machine Learning & Deep Learning then you can read it here.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Machine_Learning part 1

Machine_Learning Part 2

Deep Learning Basics

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

--

--