Traditional data types includes strings, Numbers, lists or arrays but Python has two more distinct data types. Those are tuple and dictionary.
String data type is similar to other programming. String processing and manipulation is quite simple in scripting languages like python, perl and php. Discussing few examples will give a clear picture of how a python string variable works. Continuous series of characters defined in quotes and assigned to a variable name is nothing but a string variable.
>>> test1 = "john"
>>> test2 = "Abraham"
>>>
>>> test1+test2
'johnAbraham'
Number variable is defined to have various types in it like int, long, float, complex.
>>> test1 = 20
>>> test2 = 10
>>> test1+test2
30
List variable holds a group of comma separated items in square braces. There are several commands to add, remove, select, insert, slice the list variable.
test1 = [1, 2, 3 ,4, 5]
>>> test1
[1, 2, 3, 4, 5]
Tuple is like a list holding group items in parentheses instead of square braces but it can only be read only. It means tuple cannot be manipulated in any way, it just a read only.
>>> test2 = (1, 2, 3, 4, 5)
>>> test2
(1, 2, 3, 4, 5)
In extension to the list there is another variable which holds multiple key value pair. This gives flexibility to refer an element using the key associated to it.
>>> test
{'name': 'John', 'age': '32', 'country': 'AFRICA'}
>>> test['name']
'John'
Subscribe to:
Post Comments (Atom)
Featured Post
Introduction To Groovy Programming
Starting with the first program printing "Hello World". There is no interactive shell available like other scripting langugages t...
-
Traditional data types includes strings, Numbers, lists or arrays but Python has two more distinct data types. Those are tuple and dictionar...
-
<b>First:</b> Python keywords are very basic at the stage of learning this scripting language. These are most commonly and frequ...
-
Similar to other scripting languages Python has got more support online from technical forums and strong base made it popular. It is easy to...
No comments:
Post a Comment