basics ig?? Flashcards

(35 cards)

1
Q

Binary operators

A

+ - * / work with two numbers one on either side of the symbol

these numbers are called operands

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

Unary operators

A

+ and – can be used with just one number. It will change the number from positive to negative and vice versa.

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

Syntax error

A

occurs when you type something which is not properly formed, according to the rules of the programming language.

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

Printing a string

A

print(‘text’) can also use double quotation marks

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

string + operation

A

called concatenation, adds two strings together

print(‘Hi’ + ‘Hi’ + ‘Hi’)
print(‘Hi’ * 3)

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

assignment operator

A

The = symbol is called the assignment operator, which assigns the value of the expression on the right to the variable on the left.

python reads it from right to left

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

input() function

A

get keyboard input from the user as a string.

always returns a string

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

statement

A

A statement is any valid line of Python code. Think of it like a sentence in a book.

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

expression

A

a statement which evaluates to some value.

All code involving numerical operators which we have seen so far are expressions, since they evaluate to the solution of the mathematical operation they’re performing. 9 + 11 and 3.0 / 4 are expressions. input(“Enter a number: “) is also an expression as it will evaluate to the string input by the user.

All expressions are statements, but not all statements are expressions. Only statements which evaluate to some value are expressions. (2 + 3) * (5 - 7) is both an expression and a statement.

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

int(…)

A

for positive and negative whole numbers, integers

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

float(..)

A

for real numbers such as -3.0, 0.5 or 3.14159, 1e3

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

list[…]

A

A more powerful way of storing lists of objects,
eg: [1, 3, 4] or [1.0, “hello”, “frank”]

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

print(type(…))

A

Gives the data type after the word class.

number_c = 7
print(type(number_c))
<class ‘int’>

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

int(*,+,-)int

A

int

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

int/int

A

float

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

float(*,+,-,/)float

17
Q

float(*,+,-,/)int

18
Q

int(*,+,-,/)float

19
Q

type casting

A

converting one data type into another data type

print(int(32.7))
32

print(int(“32.7”))
this fails because decimal point is not a number/digit

20
Q

modulo operator

A

% computes the remainder of an integer division

10 % 4
= 2

do long division

21
Q

Sequence

A

A sequence is like a numbered list of objects, kind of like a shopping list. All sequences have a specific ordering and can contain any number of things.

The main sequence data types we will deal with in this course are:

strings, which we have been using since worksheet 1;
lists; and
tuples

22
Q

indexing

A

To access a character at a particular position, we can specify its position number inside square brackets. This technique is called indexing or subscripting the string. The position we specify inside the square brackets is called the index. Here is an example:

s = “The number is 42.”
print(s[0])
T

counting from -> it starts at 0
counting from <- it starts at -1

23
Q

len()

A

finding the largest valid index in a string (it would be one less than the length of the string cuz it starts counting at 0)

print(len(“Hello”))
5
or

s = “The number is 42.”
n = len(s)
print(n)
17

24
Q

slicing

A

extracting a substring of arbitrary length

nameofvariable[start:end(but not include):step]

word[::-1]
it will inverse the entire variable

25
less than
< boolean
26
less than or equal
<= boolean
27
equal
== boolean
28
not equal
!= boolean
29
greater than
> boolean
30
greater than or equal
>= boolean
31
string comparisons eg: print('he' < 'hi') print('Z' < 'a')
both are true compared and sorted by alphabetical order lowercase letters are considered greater than uppercase letters
32
what are logical expressions
expressions which evaluate to a bool value eg 3 < 5
33
binary logical operator boolean inputs
false and false = F true and false = F true and true = T false or false = F true or false = T true or true = T
34
logical operators and precedence
in (relational operators) > not > and > or
35
what is a function
The basic components of a function are: the function name; the parameters; the body, where the actual computation associated with the function occurs; some mechanism for returning a value and exiting the function. def std_drinks(volume, percentage): return (volume * percentage * 0.789) The function name is std_drinks. volume and percentage are called parameters.