Topics:
Python Installation
Before you start coding make sure you have installed the python on your system.
Question: How to check whether python is installed or not? or how to check which version of python is installed on system ?
Open the window command prompt or Linux/Mac terminal, and type the below command
python –version
it will give the version of installed python, otherwise no python is installed.
To install python on your system please go the link https://www.python.org/ and download it for free.
To inter into the python command line just use the below command
python
First Program: Let’s start with famous “Hello World” program.
hadoop@prem-pc:~$ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on Linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> print(“Hello World!”)
Hello World!
to exit from the python command line use the below command
exit();
Python Indentation
Python uses indentation to indicate a block of code.
Example
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 26 22:31:40 2021 @author: mycloudplace """ def main(): if True: print("Inside True") if __name__ == "__main__": main()
Variable names and keywords
In python a variable is created when we assign any value to it. We do not need to declare the variable type before using them. It is a reserved memory location to store any value in it.
Programmers generally choose a meaningful names for their variables. Variable names can be arbitrarily long. Variable name can contain both letters and numbers.
Keywords are the reserved word which is used by interpreter to recognize the structure of the program, and they cannot be used as variable names.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 26 22:31:40 2021 @author: mycloudplace """ def main(): age = 30 #variable name of integer type name = "mycloudplace" #variable name of string type print("Age : " + str(age)) print("Name : " + name) if __name__ == "__main__": main()
Python Comments
When we write bigger program or work on big project with multiple users, it is get difficult to read the code written by other programmer. For this reason it is good idea to add notes in our programs. These notes are called comments in programming language.
Python support 2 types of comments
- Single-line comment
- Multi-line comments
Single-line comment start with #
Multi-line comments start with ”’
Example
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 26 22:31:40 2021 @author: mycloudplace """ def main(): ''' Hello This is multi-line comment! ''' print("Inside main function") #This is single line comment if __name__ == "__main__": main()
Python Programming Introduction
Pingback: Python Programming Introduction - Mycloudplace
Pingback: Python Data Types With Examples - Mycloudplace
Pingback: python iteration | while loop | for loop with examples - Mycloudplace
Pingback: Python array | numpy for python | How to create numpy or np array in python - Mycloudplace
Pingback: Modules in python tactics that can boost your python programming skills - Mycloudplace
I was extremely pleased to discover this page. I want to to thank you for ones time due to this wonderful read!! I definitely appreciated every part of it and I have you bookmarked to look at new information on your web site.
Thank you for bookmark.
Pingback: Jinja a template based python library for beautiful and interactive reports - Mycloudplace