Python Tutorial Part-1

What is Python

Python is a popular programming language which was created by Guido van Rossum. It was released in 1991.

It is used for:

  • Web Development
  • Mathematics
  • System Scripting
  • Software Development
  • Video Games
  • Artificial Intelligence
  • Machine Learning
  • Deep Learning
  • Data Science
  • Mobile Application Development, etc.

Python can do:

  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used on a server to create web applications.
  • Python can connect to database systems. It can also read and modify files.

Python works on different platforms like Windows, Mac, Linux, etc. Python has simple syntax similar to the English language. Python can be treated in a procedural way, an object-oriented way or a functional way. Python can implement scripts in fewer lines as compared to other programming languages like C, C++, Java, etc. Python also supports the Object Oriented Programming concept (oops). 



Let’s start code:

Print() Method

print(): print method is used to print the sentence or word on console or screen.

Syntax: 



print("Hello, World!")

How to check the version of python.

Check version: To check the python version in windows.

Syntax:



C:\Users\Name> python --version


How to run a Python program.

Run python program: Write a code or program in IDE (Integrated Development Environment) and then save the file with “.py” extension. Example: (program.py). Then open the command prompt on the same location, then write a command (python program.py) to run the program.

Save code: program.py

Run code: python program.py



Python Command Line

Sometimes to test a short amount of code in python. So, there is a quick and easy way to test Command Line. We can test a code in the command line or command prompt.

  • Open command prompt.
  • Write “python” or “py” into the command line.
  • Then write code to test.
  • For example: 5+10, print(“Hello World”), etc.
  • To exit from the command line, write “exit()”.

Python Indentation

Python Indentation refers to the space at the beginning of the code line. In other programming languages, the indentation is only for readability. But Indentation in python is very important. Indentation can generate the compile time error. You have to be careful.


Syntax:



# This code will compile successfully. All spaces and indentation are perfect.
a=5
b=8
If a > b:
     print(“a is greater than b”)
Else:
     print(“b is greater than a”)



# This code will give an indentation error
a=5
b=8
If a > b:
print(“a is greater than b”)
Else:
print(“b is greater than a”)


Python Variables:

Variables are created when you assign a value in it. For example: if you assign a floating point value in a variable then it will be a float variable, if you assign a string in variable then it will be a string variable.

Note: 

  • Variable names are case sensitive (Age, age and AGE are different variables). 
  • Variable names must start with character or underscore(_).
  • Variable names can’t start with a number.
  • Variable names can only contain alphanumeric characters (A-Z, a-z and _). It not contain special characters (@, -, %, /, *, $).

Syntax:



S = “Hello World”      # String type variable
X = 20                       # Integer type variable
Y = 3.5		 # float type variable
C = ‘A’			 # character type variable

Python allows you to assign multiple values in a single line.

Syntax:



→ X, Y, Z = “ Lion, Leopard, Tiger ”
print(X)	# Lion
print(Y)	# Leopard
print(Z)	# Tiger

→ X, Y, Z = 4,7,9

→ X = Y = Z = “ Programming ”
print(X)	# Programming
print(Y)	# Programming
print(Z)	# Programming

Output Variable:

We use the print() method to display the variable on the console.


Syntax and Examples are:



→ X= 3
print(“The latest version of Python is ”+X)

We use the + operator to add two or more strings.

→ S1 = “Python”
S2 = “Programming”
S3 = S1 + S2
print( S3 )

→ X = 5
Y = 7
print( X + Y )

Local and Global Variables:


→ Local variables: Variables which are created inside the function are known as Local Variables.


Note: We will learn about function in the next tutorial. Just try to understand the concept of local and global variables.


Example 1:



def  abc():
	A = 5		# Local variable
	print(A) 

abc()	# function call

→ Global Variables: Variables which are created outside the function are known as Global Variables. Global variables are accessed from both sides inside the function and outside the function.


Example 2:




A = 5		# Global variable
def  abc():
	print(A) 

abc()	# function call


Basically variables which are created inside the function are local variables. But we can make them global variables with the help of the global keyword. Just write global before the variable name. 


Example 3:



def  abc():
	A = 5		# Local variable
	global B = 8	# Global variable
	print(A) 
	print(B)

abc()	# function call
print(B) # print variable B outside the function. It will compile because B is a global variable


Video Tutorial 


Thank You !!!!!!!!


2 Comments

If you have any doubts, Please let me know

  1. I appreciate you taking the time and effort to share your knowledge. This material proved to be really efficient and beneficial to me. Thank you very much for providing this information. Continue to write your blog.

    Data Engineering Services 

    Machine Learning Services

    Data Analytics Services

    Data Modernization Services

    ReplyDelete
  2. Nice post with informative and good quality content. Thank you for sharing this information with us. This is really helpful. Also check Data Science Engineering College in India .

    ReplyDelete
Post a Comment
Previous Post Next Post