Let's write our very first python program. Create a file called hello.py and paste the below code in it:
print("Hello World") ➡️ print is a function
Execute this file(.py file) by typing python hello.py on your terminal
and you will see Hello World printed on the screen.
Modules
A module is a file containing code written by somebody else(usually) which can be imported and used in our programs.
Pip
Pip is the package manager for python you can use pip to install a module on your system
➡️ pip install numpy installs numpy module
Types of modules
There are two types of modules in Python
1. Built in modules ➡️ Pre installed in python
2. External modules ➡️ Need to install using pip
Some examples of built in modules are-
os, sys, abc, random etc.
Some examples of external modules are-
tensorflow, flask, Django, numpy etc.
Using Python as a Calculator
We can use python as a calculator by typing "python" + ↲ on the terminal.
➡️ This opens REPL or Road Evaluate Print loop
Comments
Comments are used to write something which the programmer does not want to execute.
➡️ Can be used to mark author name , date etc.
Types of Comments
There are two types of comments in Python-
1. Single line comments ➡️ Written using #
2. Multi line comments ➡️ Written using ''' comment'''
Practice Set
1. Write a program to print Twinkle twinkle little star poem in python.
2. Use REPL and print the table of 5 using it.
3. Install an external module and use it to perform an operation of your interest
4. Write a python program to print the contents of a directory using OS module. Search in OS module documentation for the function which does that.
5. Label the program written in problem 4 with comments.
Answer of practice set
1.
3.
4.
Comments
Post a Comment