--Originally published at Programming Fundaments
Python has 3 standart data types: Numbers, Strings and Lists
Number Data:
Number data types store numeric information (yeah, duh), after you insert a value to them Example:
var1 = 1
var2 = 10
String Data:
Astring, in Python, is defined as a set of character between quotation marks, and the subsets using “[ ] ” and “[ : ]”. Example:
#!/usr/bin/python
str = 'Hello World!'
print str # Prints complete string
print str[0] # Prints first character of the string
print str[2:5] # Prints characters starting from 3rd to 5th
print str[2:] # Prints string starting from 3rd character
print str * 2 # Prints string two times
print str + "TEST" # Prints concatenated string
Resulting in the next answer:
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
List data
To write a list you must assign values, using “[]” and “[:]” , and the command “list”. These values order are listed starting at 0, basically making the 0 like a 1 if we refer to the normal way to count numbers (you know, the way they taught you in elementary). Example:
#!/usr/bin/python
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print list # Prints complete list
print list[0] # Prints first element of the list
print list[1:3] # Prints elements starting from 2nd till 3rd
print list[2:] # Prints elements starting from 3rd element
print tinylist * 2 # Prints list two times
print list + tinylist # Prints concatenated lists
Creating the next result:
['abcd', 786, 2.23, 'john', 70.200000000000003]
abcd
[786, 2.23]
[2.23, 'john', 70.200000000000003]
[123, 'john', 123, 'john']
['abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john']
More examples at:http://www.tutorialspoint.com/python/python_variable_types.htm