Python Flashcards
What is the precedence of comparison operatos?
“The operators and >= all have the same level of precedence and evaluate left to right. The operators == and != have the same level of precedence and evaluate left to right. Their precedence is lower than that of and >=.”
What is cloud computing?
“Cloud computing: You can use software and data stored in the “cloud”—i.e., accessed on remote computers or servers via the Internet and available on demand—rather than having it stored locally on your desktop, notebook computer or mobile device. This allows you to increase or decrease computing resources to meet your needs at any given time, which is more cost effective than purchasing hardware to provide enough storage and processing power to meet occasional peak demands. Cloud computing also saves money by shifting to the service provider the burden of managing these apps such as installing and upgrading the software, security, backups and disaster recovery.”
What is an interpreted language?
“Compiling a large high-level language program into machine language can take considerable computer time. Interpreter programs, developed to execute high-level language programs directly, avoid the delay of compilation, although they run slower than compiled programs.”
What is a list in Python?
” One of the most common is a list, which is a comma-separated collection of items enclosed in square brackets [and]. Python only contains basically lists and dicts and sets and tuples a_list = [1, 2, 3]”
Example of matrix for in Python
“for i, row in enumeratea:\t …: for j, item in enumeraterow:\t …: printf’a[{i}][{j}]={item} ‘, end=’ ‘\t …: print”
Example of combination with map and filter
“listmaplambda x: x 2,\t …: filterlambda x: x 2 != 0, numbers”
Example of filter function
“listfilterlambda x: x 2 != 0, numbers”
Example of map function
“listmaplambda x: x 2, numbers”
Define the format of a lambda in Python
“lambda parameter_list: expression”
Example of a list comprehension
“[item for item in range1, 11 if item 2 == 0]”
How we can construct a list from a given range?
“list2 = listrange1, 6”
Put the list upside down.\t>…
“color_names.reverse”
How do we get the number of ocurrences of an element in a list?
“responses.counti”
How do we delete an element from a list?
“color_names.remove’green’”
How do we add more than one item to a list?
“color_names.extend[‘indigo’, ‘violet’]”
How do we add an item to the list?
“color_names.append’blue’”
How do we add an element to a specified position of a list?
“color_names.insert0, ‘red’”
How can we prevent an index error
“You can use the operator in to ensure that calls to method index do not result in ValueErrors for search keys that are not in the corresponding sequence:\tIn [11]: key = 1000\t\tIn [12]: if key in numbers:\t …: printf’found {key} at index {numbers.indexsearch_key}’\t …: else:\t …: printf’{key} not found’\t …:\t1000 not found”
Order a list without changing its original content.\t>…
“ascending_numbers = sortednumbers”
Order a list beginning at the end.\t>…
“numbers.sortreverse=True”
Order a list.\t>…
“numbers.sort”
Delete a member with a specific index position in a list.
“del numbers[-1]”
How can you create an empty list from a range?
“IPython Session”
Assume you have a list called names. The slice expression _____ creates a new list with the elements of names in reverse order.
Answer:
names[::-1]