Artificial Intelligence Lab Manual: Python
Artificial Intelligence Lab Manual: Python
Lab Manual
Python
Lab # 03
Python Basics
Shakeel Ahmad
LAB # 3: Data types, Containers, Input/output, and Operators in Python.
Python Strings
String is sequence of Unicode characters. We can use single quotes or double quotes or even triple quotes to
represent strings. Multi-line strings can be denoted using triple quotes, ''' or """. A string in Python consists of a
series or sequence of characters - letters, numbers, and special characters. Strings can be indexed - often
synonymously called subscripted as well. Similar to C, the first character of a string has the index 0.
Indexing:
>>>a = "hello"
>>> a[0]
>>> a[1]
>>> a[-1]
print ( a[-1] )
o(Remember that negative indices correspond to counting from the right end.)
Slicing:
Python List
List is an ordered sequence of items. It is one of the most used datatype in Python and is very
flexible. All the items in a list do not need to be of the same type. Declaring a list is , Items
separated by commas are enclosed within brackets [ ].
>>> colors = ['red', 'blue', 'green', 'black', 'white']
>>> type(colors)
14
Input columns: 2
Input number of elements in a row (1, 2, 3): 1 2
34
sum for each column: 4 6
6. Write a Python program to Zip two given lists of lists. Original lists:
[[1, 3], [5, 7], [9, 11]]
[[2, 4], [6, 8], [10, 12, 14]]
Zipped list:
[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]
15