Presentation is loading. Please wait.

Presentation is loading. Please wait.

Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.

Similar presentations


Presentation on theme: "Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel."— Presentation transcript:

1 Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel

2 2 Day 7 Python Basics

3  Memory locations reserved to store values  Variables are dynamically typed  Use the equal sign (=) to assign a value to a variable  Assign a single value to several variables simultaneously  Assign multiple values to multiple variables 3 my_variable = “hello” a = b = c = 22 name, age, height= "Bob", 22, ”5’11"

4  Variable names are case-sensitive.  A variable's name can be any legal identifier (an unlimited-length sequence of Unicode letters and digits)  Must beginning with a letter or underscore  Variables that start with an underscore (_) are treated as local and private, and cannot be imported from outside the module  When choosing a name for your variables, use full words instead of cryptic abbreviations. This will make your code easier to read and understand 4

5 Built-in FunctionsDefinition dict(iterable)Create a new dictionary enumerate(sequence, start=0)Count and iterate through the sequence eval(expression)Compiles and immediately evaluates an expression exec(expression)This statement supports dynamic execution of Python code. float(arg), int(arg), str(arg)Return a float, integer, or string constructed from the argument hasattr(object, str_arg_name)Returns true/false whether an attribute exists in an object list(iterable)Create a new list 5 View all of the Built-in functions here: https://docs.python.org/2/library/functions.html

6 Built-in FunctionsDefinition open(name, mode=r)Open a file print(objects, sep=' ')Print objects to the stream file range(start, stop[, step])Create lists containing arithmetic progressions reversed(seq)Return a reverse iterator. seqiterator round(number[, ndigits])Return the floating point value number rounded to ndigits digits sorted(iterable)Return a new sorted list from the items in iterable. zip([iterable, iterable,…])This function returns a list of tuples (2 or more dimensional list) 6 View all of the Built-in functions here: https://docs.python.org/2/library/functions.html

7  Can be concatenated: ◦ "My name is " + "Jane" ◦ "My name is " + name  Can be indexed: ◦ name = "John” ◦ name[2]  "h"  Can be sliced: ◦ name = "Geraldine" ◦ name[1:4]  "era"  Can be measured: ◦ name = "Geraldine" ◦ len(name)  9 7  Can be formatted: ◦ name = "JoHn" ◦ name.lower()  "john" ◦ name.upper()  "JOHN" ◦ name.title()  "John”  Can be repeated: ◦ name = "Bob" ◦ name*3  "BobBobBob"  Can be reversed: ◦ name = "Geraldine" ◦ name[::-1]  "enidlareG

8  Easy to create: ◦ my_list = [1,2,3] ◦ names = ["Bob", "Eva"]  Can be combined: ◦ a, b = [1, 2], [6, 7] ◦ a + b  [1, 2, 6, 7]  Can be indexed: ◦ names = ["Bob", "Eva"] ◦ names[1]  "Eva"  Can be sliced: ◦ my_list = [1,2,3,4,5] ◦ my_list[1:4:2]  [2,4] 8  Can be sorted: ◦ list = [4,2,6,8,3] ◦ list.sort()  [2,3,4,6,8]  Can be repeated: ◦ list = [1,2,3] ◦ list*2  [1,2,3,1,2,3]  Can be measured: ◦ list = ["a","b","c"] ◦ len(list)  3  Can be reversed: ◦ list = [1,2,3,4] ◦ list[::-1]  [4,3,2,1]

9  IF ◦ x = 4 ◦ if x > 0: print("yes")  IF / ELSE ◦ x = 4 ◦ if x > 0: print("yes") ◦ else: print("no") 9  Conditional assignment ◦ age = 12 ◦ name = "Bob" if age > 18 else "Bobby" IF / ELIF / ELSE x = 4 if x > 2: print("yes") elif x > 0: print("still yes") else: print(""no)

10  Iterate through a list: list_of_items = [1,2,3,4] for item in list_of_items: print('-> ' + item)  Iterate x times: x = 4 for j in range(x): print('number:', x)  Iterate and enumerate (count): items = ["apple", "orange"] for j, item in enumerate(items): print("item {0} in an {1}".format(j+1, item)) 10 -> 1 -> 2 -> 3 -> 4 number: 0 number: 1 number: 2 number: 3 item 1 is an apple item 2 is an orange

11  break: breaks out of the smallest enclosing loop for x in range(2, 6): if 8 % x == 0: print 8, 'equals', x, '*', 8/x break  continue: skips code which follows and continues with the next iteration of the loop: x = 4 for j in range(x): if x % 2 == 0: continue print x, 'is an odd number' 11 8 equals 2 * 4 3 is an odd number loop stops after x=2 print statement skipped for even numbers

12  ELSE: a loop’s else clause runs when no break occurs for x in ('a', 'b', 'c', 'd'): pass else: print('loop finished') 12 loop finished PASS statement does nothing.


Download ppt "Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel."

Similar presentations


Ads by Google