Tutorial - Day #1
Programming With Chinmay
In 100 days of code, we are going to learn Python programming From zero to job
ready. Python is a dynamically typed Object oriented programming language.
Guido van Russom was watching a show named Monty Python 's Circus On TV
when he was working on this language. He thought why not name it as Python. And
since then its name is Python. We are trying to tell computers what to do ? And we
do it with the help of programming. According to me Python is the easiest learned
programming language. There are many more programming languages in market.
But this course is going to be dedicated to Python. And this is because Python is
very easy. Python is Dynamically typed. General purpose programming language
which support object oriented paradigm. It also supports functional approach. After
that you start doing things , Then you have fun at a different level.
Installing Python in local is also very easy.
Installing Python on Windows takes a series of few easy steps.
Step 1 − Select Version of Python to Install
Python has various versions available with differences between the syntax and working
of different versions of the language. We need to choose the version which we want to
use or need. There are different versions of Python 2 and Python 3 available.
Step 2 − Download Python Executable Installer
On the web browser, in the official site of python (www.python.org), move to the
Download for Windows section.
All the available versions of Python will be listed. Select the version required by you
and click on Download. Let suppose, we chose the Python 3.9.1 version.
On clicking download, various available executable installers shall be visible with
different operating system specifications. Choose the installer which suits your system
,operating system and download the instlaller. Let suppose, we select the Windows
installer(64 bits).
The download size is less than 30MB.
Step 3 − Run Executable Installer
We downloaded the Python 3.9.1 Windows 64 bit installer.
Run the installer. Make sure to select both the checkboxes at the bottom and then click
Install New.
On clicking the Install Now, The installation process starts.
The installation process will take few minutes to complete.
Step 4 − Verify Python is installed on Windows
To ensure if Python is succesfully installed on your system. Follow the given steps −
Open the command prompt.
Type ‘python’ and press enter.
The version of the python which you have installed will be displayed if the python
is successfully installed on your windows.
Step 5 − Verify Pip was installed
Pip is a powerful package management system for Python software packages. Thus,
make sure that you have it installed.
To verify if pip was installed, follow the given steps −
Open the command prompt.
Enter pip –V to check if pip was installed.
The following output appears if pip is installed successfully.
We have successfully installed python and pip on our Windows system.
Python Quickstart
Python is an interpreted programming language, this means that as a developer
you write Python (.py) files in a text editor and then put those files into the
python interpreter to be executed.
The way to run a python file is like this on the command line:
C:\Users\Your Name>python helloworld.py
Where "helloworld.py" is the name of your python file.
Let's write our first Python file, called helloworld.py, which can be done in any
text editor.
,helloworld.py
print("Hello, World!")
Try it Yourself »
Simple as that. Save your file. Open your command line, navigate to the
directory where you saved your file, and run:
C:\Users\Your Name>python helloworld.py
The output should read:
Hello, World!
Congratulations, you have written and executed your first Python program.
Whenever you are done in the python command line, you can simply type the
following to quit the python command line interface:
exit()
Python Variables
In Python, variables are created when you assign a value to it:
x=5
y = "Hello, World!"
print(x)
print(y)
Comments
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #, and Python will render the rest of the line as a
comment:
Example
Comments in Python:
#This is a comment.
print("Hello, World!")
Casting
, If you want to specify the data type of a variable, this can be done with casting.
Example
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
Get the Type
You can get the data type of a variable with the type() function.
Example
x = 5
y = "John"
print(type(x))
print(type(y))
Many Values to Multiple Variables
Python allows you to assign values to multiple variables in one line:
Example
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Unpack a Collection
If you have a collection of values in a list, tuple etc. Python allows you to
extract the values into variables. This is called unpacking.
Example
Unpack a list:
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
Global Variables
Variables that are created outside of a function (as in all of the examples above)
are known as global variables.