Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Michael Borchardt
- # Python Introduction
- # Data Types
- # --> int && str
- # Syntax: object reference = value
- _str1 = 'i am string'
- _str2 = "i am string also"
- _int1 = len(_str1)
- print(_str1, len(_str2[::6]), _int1)
- if(len(_str2[::6]) >= 3):
- print('monkeys rule the world')
- else:
- print('no, those are republicans')
- # Changing an immutable object.
- _str1 = 'you are not a string'
- # Data Type Conversions
- print(_str1)
- print(str(45))
- # Tuples: Immutable collections of object references -- cannot be changed once created.
- _tup1 = ('1','2','3')
- print(_tup1)
- # Collecting objects of multiple data types (e.g. str/int)
- _tup2 = ('alpha',1,'bravo',2,'charlie',3)
- print(_tup2)
- print(type(_tup2))
- print(len(_tup2))
- # Lists: Mutable collections of object references -- can be changed once created.
- _list1 = ['alpha', 1, 'bravo', 2, 'charlie',3]
- print(_list1)
- print(type(_list1))
- print(len(_list1))
- # List Function: Append
- _list1.append('delta')
- _list1.append(4)
- print(_list1)
- # Specify the data type and the data types method, pass in additional arguments.
- list.append(_list1, 'echo')
- list.append(_list1, 5)
- print(_list1)
- # Calling an object reference from a certain position in the list.
- print(_list1[0], _list1[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement