Python Flashcards

Learn and remember Python syntax and functions

You may prefer our related Brainscape-certified flashcards:
1
Q

Type

A

How Python represents different types of data. Int short for integer, Str short for string, and Float for floats are all examples of types.

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

Type Casting

A

This is converting the type of data from one form to another.

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

Boolean

A

A Boolean represents one of two values: True or False.

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

Expressions

A

A type of operation that computers perform like basic arithmetic operations like adding multiple numbers.

The numbers are called “operands” and the math symbols like the plus signs are “operators”.

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

Math Operators

A

+ = Addition
- = Subtraction
* = Multiplication
/ = Division
// = Integer division (results rounded down)

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

Variables

A

Variables store values using the equals symbol (=) as an “assignment” operator.

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

Python Versions

A

The two popular versions of Python currently in use are Python2 and Python 3. Support for Python 2 is now being dropped however in favour of Python 3.

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

Comments

A

You can write a non-executable comment directly in front of code denoted with a #.

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

Strings

A

Strings are composed of a sequence of characters. They can be contained in either single or double quotes.

They can be spaces, digits or special characters.

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

Slicing Strings

A

You can return a range of characters by using the slice syntax.
Specify the start index and the end index, separated by a colon, to return a part of the string.

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

len()

A

The len() command returns the length of a string.

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

Concatenate

A

To concatenate or join variables and strings together you use the plus (+) symbol.

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

Tuples

A

Tuples are used to store multiple items in a single variable.

Tuples are one of 4 built-in types in Python with the other 3 being List, Set, and Dictionary.

Tuples are written in round brackets (). A tuple is ordered and unchangeable.

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

Escape Sequences (Characters)

A

To insert characters that are illegal in a string, use an escape character.

An escape character is a backslash \ followed by the character you want to insert.

Two backslashes \ put a “backslash” in your string.

An example of an illegal character is a double quote inside a string that is surrounded by double quotes:

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

' (Escape Character)

A

Single Quote

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

\ (Escape Character)

A

Backslash

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

\n (Escape Character)

A

New Line

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

\r (Escape Character)

A

Carriage Return

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

\t (Escape Character)

A

Tab

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

\b (Escape Character)

A

Backspace

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

\f (Escape Character)

A

Form Feed

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

\ooo (Escape Character)

A

Octal value

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

\xhh (Escape Character)

A

Hex value

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

capitalize() (String Manipulation)

A

Converts the first character to upper case

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

casefold() (String Manipulation)

A

Converts string into lower case

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

center() (String Manipulation)

A

Returns a centered string

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

count() (String Manipulation)

A

Returns the number of times a specified value occurs in a string
encode()

28
Q

endswith() (String Manipulation)

A

Returns true if the string ends with the specified value

29
Q

find() (String Manipulation)

A

Searches the string for a specified value and returns the position of where it was found

30
Q

format() (String Manipulation)

A

Formats specified values in a string

31
Q

index() (String Manipulation)

A

Searches the string for a specified value and returns the position of where it was found

32
Q

isspace() (String Manipulation)

A

Returns True if all characters in the string are whitespaces

33
Q

isnumeric() (String Manipulation)

A

Returns True if all characters in the string are numeric

34
Q

isdigit() (String Manipulation)

A

Returns True if all characters in the string are digits

35
Q

islower() (String Manipulation)

A

Returns True if all characters in the string are lower case

36
Q

isdecimal() (String Manipulation)

A

Returns True if all characters in the string are decimals

37
Q

isalpha() (String Manipulation)

A

Returns True if all characters in the string are in the alphabet

38
Q

upper() (String Manipulation)

A

Converts a string into upper case

39
Q

strip() (String Manipulation)

A

Returns a trimmed version of the string

40
Q

RegEx Module

A

re is a package built into Python that can be used to work with regular Expressions.

It’s imported using the “import re” command.

41
Q

findall (RegEx)

A

Returns a list containing all matches

42
Q

search (RegEx)

A

Returns a Match object if there is a match anywhere in the string

43
Q

split

A

Returns a list where the string has been split at each match

44
Q

sub

A

Replaces one or many matches with a string

45
Q

index()

A

This returns the position at the first occurrence of a specified value

46
Q

List

A

A list stores multiple items in a single variable or integer index. This is 1 of the 4 in-built Python data types with the other 3 being Set, Dictionary and Tuple.

47
Q

Dictionary

A

Dictionaries are used to store data values in key, value pairs.

A dictionary is a collection which is ordered (Python 3.7), changeable and does not allow duplicates.

Dictionaries are written with curly brackets {} and have keys and values.

48
Q

Sets

A

Sets are used to store multiple items in a single variable.

They’re 1 of the 4 built-in data types in Python with the other 3 being Tuple, Dictionary and List.

A set is a collection that’s unordered, unchangeable, and unindexed.

They’re written using curly brackets {}.

49
Q

union()

A

The union() method returns a set that contains all items from the original set, and all items from the specified set(s).

You can specify as many sets as desired, separated by commas.

In addition to sets union() can be used on any iterable object.

If an item is present in more than one set, the result will contain only one appearance of this item.

50
Q

Comparison Operators

A

Comparison operations compare some values and operands, then based on some condition they produce a Boolean.

51
Q

== (Comparison Operator)

A

Equal

52
Q

!= (Comparison Operator)

A

Not Equal

53
Q

> (Comparison Operator)

A

Greater than

54
Q

< (Comparison Operator)

A

Less than

55
Q

> = (Comparison Operator)

A

Greater than or equal to

56
Q

<= (Comparison Operator)

A

Less than or equal to

57
Q

Branching

A

Branching allows us to run different statements for a different input.

58
Q

Indentation

A

Python relies on indentation (whitespace at the beginning of a line) to define the scope in the code. Other programming languages often use curly-brackets for this purpose.

59
Q

If statement

A

Python conditions such as == (equals), < (less than) can be written in “if statements” and loops.

An example of this is;

a = 33
b = 200
if b > a:
print(“b is greater than a”)

60
Q

Elif

A

This is Python’s way of saying “if the previous conditions were not true, then try this condition”.

61
Q

Else

A

The else keyword catches anything which isn’t caught by the preceding conditions.

62
Q

Or (Logical Operator)

A

The or keyword is a logical operator, and is used to combine conditional statements.

It returns True is one of the statements is true.

63
Q

Not (Logical Operator)

A

The not keyword is a logical operator and is used to reverse the result of the conditional statement.

It returns False if the result is true.

64
Q

And (Logical Operator)

A

The And operator takes in 2 Boolean values and produces a new Boolean value if 2 conditions are true.

Returns True if both statements are true.

65
Q

Logical Operators

A

Logical operators (and, not, or) are used to combine conditional statements (to produce Boolean values).