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

A

print ()

21
Q

Displays on the screen and returns the line typed in

A

input ()

22
Q

Built-in subprogram:

Returns the string which matches the Unicode value of

A

chr ()

23
Q

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

A

input ()

24
Q

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

A

len ()

25
Q

Returns the integer equivalent to the Unicode string of the single character

A

ord ()

26
Q

Prints to the display

A

print ()

27
Q

Generates a list of numbers using , beginning with and up to, but not including, . A negative value for goes backwards

A

range (, , )

28
Q

Rounds x to the number of n digits after the decimal (uses the 0.5 rule)

A

round (x, n)

29
Q

List subprogram:

Adds to the end of the list

A

.append ()

30
Q

List subprogram:

Removes the item at from list

A

del list[index]

31
Q

List subprogram:

Inserts item just before an existing one at index

A

List.insert (index, item)

32
Q

List subprogram:

Two methods of creating a list structure. Both are empty

A

aList = list ()

aList = []

33
Q

String subprogram:

Returns the length of

A

len ()

34
Q

String subprogram:

Returns the location of in the original . Returns -1, if not found

A

String.find (substring)

35
Q

String subprogram:

Returns the location of in the original . Raises an exception if not found

A

String.index (substring)

36
Q

String subprogram:

Returns True, if all characters are alphabetic, A–Z

A

.isalpha ()

37
Q

String subprogram:

Returns True, if all characters are alphabetic, A–Z and digits (0–9)

A

.isalnum ()

38
Q

String subprogram:

Returns True, if all characters are digits (0–9), exponents are digits

A

.isdigit ()

39
Q

String subprogram:

Returns original string with all occurrences of replaced with

A

String.replace (s1, s2)

40
Q

String subprogram:

Returns a list of all substrings in the original, using as the separator

A

String.split (char)

41
Q

String subprogram:

Returns original string with all occurrences of char removed from the front and back

A

.strip (char)

42
Q

String subprogram:

Returns the original string in uppercase

A

.upper ()

43
Q

String subprogram:

Returns the original string in lowercase

A

.lower ()

44
Q

String subprogram:

Returns True, if all characters are uppercase

A

string.isupper ()

45
Q

String subprogram:

Returns True, if all characters are lowercase

A

.islower ()

46
Q

String subprogram:

Formats values and puts them into the

A

string.format (placeholders)