Friday , June 18 2021
Home / Python / Python Basic Syntax
Python Basic Syntax - Python Identifiers, Reserved Words, Lines and Indentation

Python Basic Syntax

Python Basic Syntax

Introduction to Python Programming Language

What is Python?

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

It is used for:

  • artificial intelligence
  • big data
  • web development (server-side)
  • software development
  • mathematics
  • system scripting

First Python Program

In [1]:
print("www.machinelearning.org.in")
www.machinelearning.org.in
In [2]:
print("Python")
print("Data Science")
print("Machine Learning")
Python
Data Science
Machine Learning

Single Line Comment

Comments start with a #, and Python will render the rest of the line as a comment:

In [5]:
print("Hello")  #This is a comment
Hello
In [3]:
print("Python")
print("Data Science")
#print("Machine Learning")
print("Deep Learnig")
print("Artificial Intelligence")
Python
Data Science
Deep Learnig
Artificial Intelligence

Multiline Comment

Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it:

In [4]:
'''
print("Python")
print("Data Science")
print("Machine Learning")
print("Deep Learnig")
'''
print("Artificial Intelligence")
Artificial Intelligence

Assign Value to a variable

In [9]:
a=10
b=3.134
c="Machine Learning"
In [10]:
print(a)
print(b)
print(c)
10
3.134
Machine Learning
In [11]:
print("Value of a :",a)
print("Value of b :",b)
print("Value of c :",c)
Value of a : 10
Value of b : 3.134
Value of c : Machine Learning
In [12]:
print(a,b,c)
10 3.134 Machine Learning
In [13]:
print("Value of a :",a,"Value of b :",b,"Value of c :",c)
Value of a : 10 Value of b : 3.134 Value of c : Machine Learning
In [14]:
print("Value of a :",a,"\nValue of b :",b,"\nValue of c :",c)
Value of a : 10 
Value of b : 3.134 
Value of c : Machine Learning
In [15]:
print("Value of a :",a,end='\n')
print("Value of b :",b,end='\n')
print("Value of c :",c,end='\n')
Value of a : 10
Value of b : 3.134
Value of c : Machine Learning
In [17]:
print("Value of a :",a,end=' ')
print("Value of b :",b,end=' ')
print("Value of c :",c,end=' ')
Value of a : 10 Value of b : 3.134 Value of c : Machine Learning 

Accepting User Inputs

input( ) accepts input and stores it as a string. Hence, if the user inputs a integer, the code should convert the string to an integer and then proceed.

In [18]:
a=input("Enter any value:")
print(a)
Enter any value:Machine Learning
Machine Learning
In [19]:
print(type(a))
<class 'str'>

Note that type( ) returns the format or the type of a variable or a number

About Machine Learning

Check Also

Python MySQL Insert Into Table

4 Python MySQL Insert Into Table Python MySQL Insert Into Table¶To fill a table in …

Leave a Reply

Your email address will not be published. Required fields are marked *