Python syntax Flashcards

1
Q

Data types - in python syntax

Integer
Real
Boolean
Character

A

int
float
bool
str

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Convention of data types into 
Integer
Real
Boolean
List
A

Conversion is used to transform the data types of the contents of a variable using int(), str(), float(), bool() or list().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How constants conventionally named

A

Constants are conventionally named in all uppercase characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A structured data type is a sequence of items, which themselves are typed. Sequences start with an index of __.

A

Zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Array vs record in python explanation + syntax

A

Array - A sequence of items with the same (homogeneous) data type list

Record - A sequence of items, usually of mixed (heterogenous) data types list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Arithmetic operators:

division
multiplication
exponentiation
addition
subtraction
integer division
modulus
A
/
*
**
\+
-
//
%
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Relational operators

equal to
not equal to
greater than
greater than or equal to
less than
less than or equal to
A
==
!=
>
>=
<
<=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Logical/Boolean operators

  • both sides of the test must be true to return true
  • either side of the test must be true to return true
  • inverts
A

and
or
not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Assignment

A

=

=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Selection —- all

A

if :

if :
else:

if :
elif :
else:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Repetition

Pre-conditioned loop. This executes while is true.

A

while :

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Iteration -

Executes for each element of a data structure, in one dimension

A

for in :

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Count-controlled loop. Executes a fixed number of times, based on the numbers generated by the range function

A

for in range (, ):

for in range (, ):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In range - what is inclusive and what is exclusive ?

A

for in range (, ):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Count-controlled loop. Executes a fixed number of times, based on the numbers generated by the range function

influences the numbers generated by the range function

A

for in range (start, stop, step):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to define a procedure with no parameters

A

def ():

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to define a procedure with parameters

A

def (, ):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to define a function with no parameters

A

def ():

return ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to define a function with parameters

A

def (, ):

return ()

20
Q

Displays on the screen

21
Q

Displays on the screen and returns the line typed in

22
Q

Built-in subprogram:

Returns the string which matches the Unicode value of

23
Q

Displays the content of prompt to the screen and waits for the user to type in characters followed by a new line

24
Q

Returns the length of the , such as a string, one-dimensional or two-dimensional data structure

25
Returns the integer equivalent to the Unicode string of the single character
ord ()
26
Prints to the display
print ()
27
Generates a list of numbers using , beginning with and up to, but not including, . A negative value for goes backwards
range (, , )
28
Rounds x to the number of n digits after the decimal (uses the 0.5 rule)
round (x, n)
29
List subprogram: Adds to the end of the list
.append ()
30
List subprogram: Removes the item at from list
del list[index]
31
List subprogram: Inserts item just before an existing one at index
List.insert (index, item)
32
List subprogram: Two methods of creating a list structure. Both are empty
aList = list () aList = []
33
String subprogram: Returns the length of
len ()
34
String subprogram: Returns the location of in the original . Returns -1, if not found
String.find (substring)
35
String subprogram: Returns the location of in the original . Raises an exception if not found
String.index (substring)
36
String subprogram: Returns True, if all characters are alphabetic, A–Z
.isalpha ()
37
String subprogram: Returns True, if all characters are alphabetic, A–Z and digits (0–9)
.isalnum ()
38
String subprogram: Returns True, if all characters are digits (0–9), exponents are digits
.isdigit ()
39
String subprogram: Returns original string with all occurrences of replaced with
String.replace (s1, s2)
40
String subprogram: Returns a list of all substrings in the original, using as the separator
String.split (char)
41
String subprogram: Returns original string with all occurrences of char removed from the front and back
.strip (char)
42
String subprogram: Returns the original string in uppercase
.upper ()
43
String subprogram: Returns the original string in lowercase
.lower ()
44
String subprogram: Returns True, if all characters are uppercase
string.isupper ()
45
String subprogram: Returns True, if all characters are lowercase
.islower ()
46
String subprogram: Formats values and puts them into the
string.format (placeholders)