(GCSE ARCHIVE) Python Concepts & Syntax Flashcards

1
Q

Statement

A

A single instruction or step within a program

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

Record

A

A data structure that stores elements, as a series of attributes, used in databases.

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

Variable

A

A data element in a program whose value can change as the program is running

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

Constant

A

A data element in a program whose value does not change as the program is running

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

Input

A

Data introduced into a computer system from the outside world

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

Output

A

Data that is presented to the outside world, such as by a printer or display

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

Function

A

A named set of instructions that returns a value

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

Procedure

A

A named set of instructions that does not return a value

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

Assignment

A

The process of allocating a value to a data element

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

String

A

A data type capable of storing combinations of numbers, letters and symbols

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

Iteration

A

A type of programming construct in which a group of statements is executed repeatedly

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

Selection

A

Program construct in which a condition is used to decide which instructions (if any) will be executed

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

Sequence

A

Program construct in which a set of instructions are executed in the order in which they appear

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

Casting

A

The process of converting one data type into another data type

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

How to assign a string, integer, float, and Boolean in python

A
  • bob = “string”
  • john = 19
  • david = 3.14
  • sam = True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to convert a variable into a string, integer or float for concatenation. Rules for each one.

A

str(variable)
int(variable)
float(variable)

  • String works for any data type
  • Int only works integer strings (“12”) and truncates floats (12.8 becomes 12).
  • Float only for integers and whole number string (“12” or 12 becomes 12.0)
17
Q

How to make a user input a string, integer, float

A
  • string = input(“Enter a string:”)
  • integer = int(input(“Enter an integer”))
  • float = float(input(“Enter a float”))
18
Q

Arithmetic operators in python for addition, subtraction, multiplication, division, integer division, remainder.

A

Addition) +
Subtraction) -
Multiplication) *
Division) /
Integer Division) //
Remainder) %

19
Q

Boolean operators in python, not equal to, less than or equal to, and greater than or equal to.

A

Not equal to) !=
Less than or equal to) <=
Greater than or equal to) >=

20
Q

Return the number of characters in a string

A
  • len(string)
  • counting starts starts at 1

name = “Faisal”
print(len(name))

6

21
Q

How to return the position of the first occurennce of a particular value in a string.

A
  • string.index(substring)
  • starts counting from 0, as it is an index

string = “Faisal”
print(string.index(“F”))

0

22
Q

How to extract a character at a certain position in a string

A
  • string[x]
  • starts counting from 0, as it is an index

string = “Faisal”
print(string[0])

F

23
Q

How to make a string all uppercase

A
  • string.upper()

string = “Faisal”
print(string.upper())

FAISAL

24
Q

How to make a string all lowercase

A
  • string.lower()

string = “Faisal”
print(string.lower())

faisal

25
Q

How to extract a substring from one point to another

A
  • string[x:y]
  • be careful, as this starts counting from 1, unlike regular index.
  • you could subtract (y-x) to get length

string = “Faisal”
print(string[3:6])

sal

26
Q

How to check if a string contains only digits

A
  • string.isdigit()

age = 8
print(age.isdigit())

True

27
Q

How does string concatenation work? Example.

A

name1 = “Faisal”
name2 = “Mohammad”

print(name1+ name2)
FaisalMohammad

print(name1, name2)
Faisal Mohammad

28
Q

How do lists work in python?

A
  • They work the same way as arrays. This is a 2D array list:

vowels = [“a”, “e”, “i”, “o”, “u”]
print(vowels[0])
print(len(vowels))

a
5

29
Q

How to make 2D lists/arrays in python?

A

listTwo = [[1, 2, 3], [4,5,6]]
print(listTwo[1])
print(listTwo[0][1])

[4, 5, 6]
2