91-9990449935 0120-4256464 |
Python VariablesVariable is a name of the memory location where data is stored. Once a variable is stored that means a space is allocated in memory. Assigning values to Variable:We need not to declare explicitly variable in Python. When we assign any value to the variable that variable is declared automatically. The assignment is done using the equal (=) operator. Eg: Output: >>> 10 ravi 20000.67 >>> Multiple Assignment:Multiple assignment can be done in Python at a time. There are two ways to assign values in Python: 1. Assigning single value to multiple variables: Eg: x=y=z=50 print x print y print z Output: >>> 50 50 50 >>> 2.Assigning multiple values to multiple variables: Eg: a,b,c=5,10,15 print a print b print c Output: >>> 5 10 15 >>> The values will be assigned in the order in which variables appears. Basic Fundamentals:This section contains the basic fundamentals of Python like : i)Tokens and their types. ii) Comments a)Tokens:
There are following tokens in Python:
Tuples:
Eg: >>> tuple=('rahul',100,60.4,'deepak') >>> tuple1=('sanjay',10) >>> tuple ('rahul', 100, 60.4, 'deepak') >>> tuple[2:] (60.4, 'deepak') >>> tuple1[0] 'sanjay' >>> tuple+tuple1 ('rahul', 100, 60.4, 'deepak', 'sanjay', 10) >>> Dictionary:
Eg: >>> dictionary={'name':'charlie','id':100,'dept':'it'} >>> dictionary {'dept': 'it', 'name': 'charlie', 'id': 100} >>> dictionary.keys() ['dept', 'name', 'id'] >>> dictionary.values() ['it', 'charlie', 100] >>>
Next TopicPython keywords
|