Python Programming Grammar Flashcards

1
Q

List

A

A collection of data of one or more types within square brackets

[“hello”, 0, 1.5, 3]

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

Quotient

A

A quotient is the number obtained by dividing one number by another. It can be an int or float.

For example, if you divide 6 by 3, you get 2, which is the quotient.

It is the answer from the division process.

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

Remainder (modulus) %

A

After you divide two numbers and get the quotient. The number left over is called the remainder.

Modulus (or “mod”, for short) returns the remainder of dividing one number by another number. e.g. 15 % 10 will return 5.

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

Difference between quotient and the remainder (modulus)

A

The number of times we have subtracted is called the quotient (of the division of by ) The number that is leftover from after subtracting as often as possible is called the remainder (of the division of by ).

In integer division and modulus, the dividend is divided by the divisor into an integer quotient and a remainder. The integer quotient operation is referred to as integer division, and the integer remainder operation is the modulus.

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

Dividend

A

The number that you are dividing

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

Division in Python

A

The dividend, divisor, quotient and remainder.

In Division, the number which we divide is called the dividend. The number by which we divide is called the divisor. The result obtained is called the quotient. The number left over is called the remainder.

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

Divisor

A

The number by which we divide is called the divisor.

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

Float

A
Real value (decimal)
Also known as floating-point number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Integer / Int

A

A number with no decimal

A whole number

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

String / Str

A

A collection of characters within single or double quotes

“hello”, ‘hello’

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

Truncate / /

A

Shorten the duration or extent of

Look for other definitions. This one seems lacking.

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

Syntax

A

the arrangement of words and phrases to create well-formed sentences in a language.

a set of rules for or an analysis of the syntax of a language.
plural noun: syntaxes
“generative syntax”

the branch of linguistics that deals with syntax.

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

Packages

A

Researchers, mathematicians, and data scientists in particular like Python because of its rich and easy to understand syntax and the wide range of open-source packages available. Packages are commonly used, shared code libraries that are freely available for anyone to use.

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

Learning the pythonic way

A

Python is supported by an active user community that is eager to help new programmers learn the Pythonic way, where you don’t just get the syntax right, but use the language the way it was intended.

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

Python is an interpreted language which reduces the ____________
Because there’s no _______________.

A
  1. edit-test-debug cycle

2. no compilation step required.

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

In order to run Python apps, you need a ______________

A

runtime environment/interpreter to execute the code.

17
Q

Most of the runtime environments/ interpreters support two ways to execute Python code:

A

Interactive mode and Script mode

18
Q

Interactive mode

A

in this mode, each command you type is interpreted and executed immediately, and you see the results each time you press ENTER. The interactive mode is the default mode if you don’t pass a filename to the interpreter.

19
Q

Script mode

A

in script mode, you put a set of Python statements into a text file with a .py extension. You then run the python interpreter and point it at the file. The program is executed line by line, and the output is displayed. There is no compilation step, as shown in the following diagram:

.py 👉 Python interpreter 👉 results

20
Q

“Read-Eval-Print-Loop”, or REPL.

A

Python supports an interactive console experience, which allows you to type in commands and see the results immediately. This experience is sometimes referred to as a “Read-Eval-Print-Loop”, or REPL.

21
Q

How to use REPL

A

To use the REPL, type python in your console. You will get is a prompt similar to the below output, which then waits for you to input commands:

Output
—————
Python 3.9.5 (default, May 27 2021, 19:45:35)
[GCC 9.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
»>

22
Q

What can REPL do?

A

Run and evaluate statements. You can have the REPL evaluate a statement like so:

Output
————
>>> 1+1
2
>>>

Or

Declare variables and functions. You can also create variables and functions, and REPL will remember that they exist, should you try to use them later:
Output

> > > PI = 3.14
PI
3.14

Or Use the built-in help. Getting help on a topic can be useful, as you don’t have to leave the editor of your choice, to browsing on the Web, but you can continue to author code.

23
Q

Using help: The REPL has a built-in help function you can use to look up keywords and functions.

A

The REPL has a built-in help function you can use to look up keywords and functions. The generalized syntax for this function is:
Python

Copy
help([object])
Where [object] is a specific function or keyword you want help on.

24
Q

Variables

A

Variables are one of the fundamental building blocks of programs written in Python. Variables hold data in memory. They have names, and they can be referenced by those names. Variables also havetypes, which specify what type of data they can store (such as string and integer), and they can be used in expressions that useoperators(such as+and-) to manipulate their values.

In Python, a variable is declared and assigned a value using the assignment operator =. The variable is on the left-hand side of the operator, and the value being assigned — which can be an expression such as 2 + 2 and can even include other variables — is on the right-hand side:
Python

Copy
x = 1 # assign variable x the value 1
y = x + 5 # assign variable y the value of x plus 5
z = y # assign variable z the value of y
These examples assign numbers to variables, but numbers are just one of several data types Python supports. Notice there’s no type declared for the variables. This is because Python is a dynamically typed language, meaning the variable type is determined by the data assigned to it. In the examples above, the x, y, and z variables are integer types, capable of storing positive and negative whole numbers.
Variable names are case sensitive and can use any letter, number, and the underscore (_) character. However, they can’t start with a number.

25
Q

In Python, a variable is declared and assigned a value using the assignment operator _______.

A

=

The variable is on the left-hand side of the operator, and the value being assigned — which can be an expression such as 2 + 2 and can even include other variables — is on the right-hand side:
Python

Copy
x = 1 # assign variable x the value 1
y = x + 5 # assign variable y the value of x plus 5
z = y # assign variable z the value of y

These examples assign numbers to variables, but numbers are just one of several data types Python supports. Notice there’s no type declared for the variables. This is because Python is a dynamically typed language, meaning the variable type is determined by the data assigned to it. In the examples above, the x, y, and z variables are integer types, capable of storing positive and negative whole numbers.
Variable names are case sensitive and can use any letter, number, and the underscore (_) character. However, they can’t start with a number.

26
Q

Types for integers and decimals

A

Python creates integers from a built-in data type called int, and decimals (floating-point numbers) as instances of float. Python’s built-in type() function returns a variable’s data type. The following code outputs data types:
Python

Copy
x = 1
print(type(x)) # outputs:

x = 1.0
print(type(x)) # outputs:
The addition of the “.0” to the end of “1” makes a large difference in how the programming language treats a value. The data type impacts how the value is stored in memory, how the processor (CPU) handles the data when evaluating expressions, how the data relates to other data, and what kinds operations you can perform with it.

27
Q

Determining types of objects

A

Int, float, string

To determine the type of an object, we use the functiontype. We can call the functiontypeon aliteralvalue such as the integer3or string”hello”, or a variable that holds a value such asxorword.

E.g
type(1)
The above would run as int

X = 1
The above would run as int

Type(‘hello’)
The above would run as str

word = “hello”
type(word)
The above would run as str

28
Q

Almost all data in Python is stored as ______.

A

Objects

29
Q

True or false:

Comments in code must have a space in between the # and the comment

A

this is an example of wrong usage of a comment. The computer will not recognize it.

True. There must always be a space between the comment # and the comment. E.g
# this is a line of code 
30
Q

True or false:

Comments cannot be on the same line as code

A

False.
Comments can be put right after code. They do not have to be on a separate line.

E.g
X = 1 # this comment can go here