Assigning Values in Python

In Python we can assign values very easily. Like PHP it is also loosely typed. You need not declare the type of value.


#!/usr/bin/python3

a = 1
b = "b"
c = (1,2,4,8)
d = ['mana', 'babu', 'hagudu']
e = {'name':'mana', 'age':7, 'look':'sweet'}

def main():
    print(type(a), a)
    print(type(b),b)
    print(type(c),c)
    print(type(d),d)
    print(type(e),e)

if __name__ == "__main__":
    main()

In python everything is object and has an associated class along with it and we can have an output like this:

# 1
# b
# (1, 2, 4, 8)
# [‘mana’, ‘babu’, ‘hagudu’]
# {‘look’: ‘sweet’, ‘name’: ‘mana’, ‘age’: 7}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s