Revision w6-w15 Flashcards

1
Q

assignment operator

A

=

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

To define a variable you must ..?

A

The name of the variable

The initial value of the variable

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

Any words that are reserved for special

purposes in a computer language

A

Reserved words

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

Name Python’s data types:

A

int, float, string, complex numbers and Boolean

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

True or False?

The data type is associated with the value, not the variable

A

True

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

Is Python a dynamically or statically typed language?

A

Python is a dynamically typed language, in other words, the

variables data type can change during runtime

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

num=1
str=’s’
num2=2

satuation1: num + s
satuation2: num + num2

what is the output?

A

1: error
2: 3

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

Can a constant value change?

A

Yes

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

Is Python a interpreted or compiled language?

A

Python is an interpreted language —it does not use a compiler.

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

What is the difference between ‘/’, ‘//’ and ‘%’?

A
/ --> prints float
//--> (Floor division) discards the fractional part
% --> (modulus division), return the remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between ‘*’ and ‘**’?

A
  • –> multiplication

* * –> power

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

The values passed to the function.

A

Arguments

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

What are the four ways to import sqrt() from math:

A

1- from math import sqrt
2- import math –> math.sqrt()
3- import math as m –> m.sqrt()
4- from math import ∗ (imports all functions, but it is not recommended)

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

Formatting:

A

age = 18
num=1
print( f “Im { age } today ” )
print(f“ Cost {age + num}”)

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

Formating

A

look w-8a Page-8 to 11 VERY IMPRTANT INFO

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

Strings are right justified by default

TRUE OR FALSE?

A

FALSE

17
Q

num > num2 + 1
The comparison operators have higher precedence than arithmetic operators?
TRUE OR FALSE?

A

FALSE

Calculations are done before the comparison

18
Q

How to print ‘’ or ‘?

A

’ “ ‘ OR “ ‘ “. They must be opposite

19
Q

What will be printed?
name = ‘Rand’ + ‘AB’
name2 = ‘Rand’, ‘AB’

A
name = RandAB
name2 = Rand AB
20
Q

What is concatenating strings?

A

str1 + str2

using (+) to connect strings

21
Q

a sequence of characters used inside a

string literal that translates into another character

A

An escape sequence ()
\n
\t
\

22
Q

Can you use (< or >, like str[1] > str[2]) with letters?

A

Yes.

space then numbers then uppercase then lower

23
Q

Method vs Function

A

Unlike a function, a method can only be applied to an object
of the type for which it was defined
Methods are specific to a type of object

24
Q

String methods:

A

upper() and lower()
replace(old, new) ->
Ex: name . r e p l a c e ( “ ohn ” , “ames ” )

25
Q

while-loops can be controlled by?

A

An event
A counter
A sentinel value.
A flag variable (boolean)

26
Q

a special value (or character) used to

terminate a loop

A

A sentinel value.
For numeric input of positive numbers, it is common to use
−1

27
Q

A for-loop:

A
  • The number of iterations is known in advance.

- can be used to iterate over a container.

28
Q

A segment of code that performs a specific task

A

A function

29
Q

Before you implement your function:

A

know what the function should do, the inputs and what it returns.

30
Q

Parameter Vs Argument

A

Parameter -> coder

Argument -> user

31
Q

variables used to

pass values to a function

A

parameters

32
Q

Do not modify parameter variables!!!!!

A

.

33
Q

how to return more than one value?

A
def function():
    return x1, x2

num1, num2 = function()

34
Q

The function can generate output even when it doesn’t have a
return value
True OR False?

A

True

35
Q

You cannot use the return statement without a value

True OR False?

A

False. you can, it will terminate the function

36
Q

When function definition order does and doesn’t matters

A

matters: when they aren’t inside the main()

doesn’t matter: when they are inside the main()

37
Q

An easy way to add a block of a list’s values? ex, to add from index 5 to index 17

A

sum(lst[ 5 : 18 ])