Python is a widely used high-level programming language created by Guido van Rossum and first released in 1991.
A Python identifier is a name used to identify a variable, function, class, module or
An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters,
var1 = 1
var2 = 10
These are reserved words and you cannot use them as constant or variable or any other identifier names. All the Python keywords contain lowercase letters only.
Examples -
and , exec, for, if etc.
Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
var1 = 1 var2 = 10
name = "John"
Python has five standard data types −
Numbers
Dictionary
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
Lists
In Python list can be written as a list of comma-separated values (items) between square brackets
list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5]
Dictionary
Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces.
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} print "dict['Name']: ", dict['Name'] print "dict['Age']: ", dict['Age']
Functions
A function is a block of organized, reusable code that is used to perform a single, related action.
def printme( str ):
"This prints a passed string into this function"
print str
return
def functionname( parameters ):
"function_docstring"
function_suite
return [expression]
Example -
Tuples
A tuple is a sequence of immutable Python objects.
#!/usr/bin/python tup1 = ('physics', 'chemistry', 1997, 2000); tup2 = (1, 2, 3, 4, 5, 6, 7 ); print "tup1[0]: ", tup1[0] print "tup2[1:5]: ", tup2[1:5]