Python 1 Flashcards

1
Q

What are the 2 methods to start Python on your PC?

A

-IDLE- A cross-platform Python development enviornment, called Intehrated Development Enviorment or simply IDE

-Python Shell- running ‘python’ from the Command Line

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

How to start Python from the command line.

A

-Type ‘cmd’ at the Window search bar
-Type ‘python’ at the command line. Python Shell appears.

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

Starting Python with IDLE.

A

-Open console or command-line interface by typing ‘cmd’ at the Window search
-Type ‘idle’ at the command line. The IDLE Shell appears.

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

How does IDLE help you program in Python by:

A

-Coloring-coding your program
-Debugging
-Auta-indent
-Interactive shell

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

How to make a comment?

A

-Add a hashtag before

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

What colors are comments, string, and outputs.

A

-Comments are red
-Strings are green
-Output is blue

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

What is a syntax?

A

The set of legal structures and
commands that can be used in a particular
programming language.

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

What is a code or source code?

A

The sequence of instructions in a program

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

What is output?

A

The messages printed to the user by a program

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

What is a console?

A

The textbox onto which output is printed

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

What is compiling?

A

Translates your program into a form that a machine understands.

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

What is interpreting?

A

Directly interpreted into machine instructions

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

What is a variable?

A

A named piece of memory that can store a value.

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

How to make a variable

A

name=value
ex:
- x = 10
- name = “Sarah”

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

Rules for naming variables

A

Legal variable names:
-Can only contain letters, numbers, and underscores.
-Cannot start with a number

Good variable names:
-Choose descriptive names
-Be consistent
-Keep the length in check

Illegal names:
-If it starts with a number
-If it is one of pythons keywords

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

What happens if you get an illegal name

A

You get a syntax error
ex:
“SyntaxError: invalid syntax”

14
Q

What does print do?

A

Produces text output on the console

15
Q

What do you input to get the output Hello, world!?

A

(‘Hello, world!”)

16
Q

How to prevent it from making a new line?

A

Specify that it should end with a blank
ex:
print(‘a’, end=’ ‘)
print(‘b’, end=’ ‘)
print(‘c’)
Output: a b c

17
Q

What are the 2 number types?

A

-Integers (e.g. -3,-2, 0)
-Floating point (e.g. -23,2,3.14)

18
Q

What are operators and operands?

A

-Operators are special symbol that represent computations like addition and multiplication
eg: “ + - X”

-Operators are the values the operators are applied to
eg “1 + 2”
1 and 2 are the operands
+ is the operators

19
Q

What do these signs mean and their order of evalutation?
- +
- -
- *
- /
- %
- **
-//

A
  • +, Addition, Left to right, 5+3=8
  • ”-“ Minus, Left to right, 5-3=2
  • , Multiply, Left to right, 53=15
    Division, Left to right, 15/3=15
  • %. Modulus, Left to right, 5 % 2=1
  • . Square, Right to left, 52=25
  • //, Integer division and only the whole number is returned, right to left, 5//2=2
20
Q

What are the keywords in Python?

A

-and
-as
-assert
-break
-class
-continue
-def
-del
-elif
-else
-except
-exec
-finally
-for
-from
-global
-if
-import
-in
-is
-lambda
-not
-or
-pass
-print
-raise
-return
-try
-while
-with
-yield

21
Q

Explain the order of operations of python

A

-Do what is in parentheses first
-Then ** Right to left
-Then *, /, % left to right
-Then +, - left to right

22
Q

What does the division operator produce?
and answer these and explain why.
-15.0/2.0=
-15 / 2 =
-1 / 2.0 =

A

The division operator always produces a real number
-7.5
-7.5
-0.5

23
Q

What does the integer division operator do? and answer these questions
»> minute = 59
»> minute//60
=?
»> minute = 59
»> minute //60.0
=?

A

Performs floor division on the result of division
-0, as both numbers dont have a decimal
-0.0 as one of the numbers is a floating point number so the result is a float