Presentation is loading. Please wait.

Presentation is loading. Please wait.

More Python Proglan Python Session 2. Lists  Lists are like flexible arrays. They can contain as many variables as you wish, and all variable types are.

Similar presentations


Presentation on theme: "More Python Proglan Python Session 2. Lists  Lists are like flexible arrays. They can contain as many variables as you wish, and all variable types are."— Presentation transcript:

1 More Python Proglan Python Session 2

2 Lists  Lists are like flexible arrays. They can contain as many variables as you wish, and all variable types are supported. List items can be iterated over (will be explained further in the tutorial) or accessed using a zero-based index.

3 Lists mylist = [] mylist.append(1) mylist.append(2) mylist.append(3) print mylist[0] # prints out 1 print mylist[1] # prints out 2 print mylist[2] # prints out 3 # prints out 1,2,3 for x in mylist: print x

4 List Error  Accessing an index which does not exist generates an error. mylist = [1,2,3] print mylist[10]

5 Basic Operators

6 Arithmetic Operators  Just as any other programming languages, the addition, subtraction, multiplication, and division operators can be used with numbers. number = 1 + 2 * 3 / 4.0

7 Modulo (%) Operator  Returns the integer remainder of the division. divided % divisor = remainder. remainder = 11 % 3

8 Power Relationships  Using two multiplication symbols makes a power relationship. squared = 7 ** 2 cubed = 2 ** 3

9 Using Operators with Strings  Python supports concatenating strings using the addition operator: helloworld = "hello" + " " + "world"  Python also supports multiplying strings to form a string with a repeating sequence: lotsofhellos = "hello" * 10

10 Using Operators with Lists  Lists can be joined with the addition operators: even_numbers = [2,4,6,8] odd_numbers = [1,3,5,7] all_numbers = odd_numbers + even_numbers  Just as in strings, Python supports forming new lists with a repeating sequence using the multiplication operator: print [1,2,3] * 3

11 End of Presentation Thank you for paying attention!


Download ppt "More Python Proglan Python Session 2. Lists  Lists are like flexible arrays. They can contain as many variables as you wish, and all variable types are."

Similar presentations


Ads by Google