Monday, July 25, 2011

Python Data Types Code Example - පයිතන් දත්ත වර්ග

x = []
for i in range(0,10):
    x.append(i)
print x
print "______________________________________"

y = x * 10

x = "Hello World!"

print x
print "______________________________________"
print y

# What are X and Y?

===================================



#############
# Arithmetic
#############
4 + 4 == 8
3 - 5 == -2
16 / 2 == 8
16 * 4 == 64
3 % 2 == 1 # Modulus

# Long Int Conversion - Useful for function type mismatches - Not needed here.
100000000000000000000L + long(100) == 100000000000000000100L

======================

##########
# Strings
##########

a = "Hello"
b = "World!"

# Concatenation
a + " " + b == "Hello World!"

# Repetition and Concatenation
a * 3 + " " + b == "HelloHelloHello World!"
(a + " ") * 3 + b == "Hello Hello Hello World!"

# Indexing
b[2] == "r"

# Conversion of data to string - Sesame Street:
c = 7 # Backquote ` ` or str() operations
( a + " number " + `c` ) and ( a + " number " + str(c) ) == "Hello number 7"


============================




1 comment: