Unit 2 Flashcards

1
Q

is just a file of Python code, which can include
statements, function definitions, and class definitions

A

module - a script or a short Python program, can be contained in one module

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

contains the starting point of program
execution

A

main module

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

contain function and class definitions

A

supporting modules

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

the types of words or symbols used to construct sentences
▪ some basic symbols are keywords, such as if, while, and
def

A

Lexical Elements

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

Python keywords and names are _________

A

case-sensitive - while is a keyword, While is a programmer-defined name

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

− named locations in computer memory
− languages define rules for naming variables
− should have meaningful names

A

Variables

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

In Python, a variable is created when you assign a value to
it. It has no command for declaring a variable.

A

yeah

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

A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).

A

yeah

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

Rules for Python variables:

A
  • a variable name must start with a letter or the underscore
    character
  • a variable name cannot start with a number
  • a variable name can only contain alpha-numeric characters
    and underscores (A-z, 0-9, and _)
  • variable names are case-sensitive (age, Age and AGE are
    three different variables)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

nouns or adjectives: denote Boolean values

A

variable names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  • verbs: denote actions
  • nouns or adjectives: denote values returned
A

function and method names

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

the types of sentences (expressions, statements, definitions,
and other constructs) composed from the lexical elements

A

Syntactic Elements

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

indentation and line breaks are ___________ in Python code

A

significant

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

Python uses _____________________ to mark the syntax of many types of sentences

A

white space (spaces, tabs, or line breaks)

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

Literals

A

❑Numbers
* integers or floating-point numbers are written as they are in
other programming languages
❑The Boolean values True and False are keywords
❑Some data structures, such as tuples, lists, and dictionaries,
also have literals

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

Data Typing

A

− any variable can have a value of any type
− variables are not declared to have a type, they are simply
assigned a value
− all values or objects have types

17
Q

True/False: any variable can’t have a value of any type

A

False

18
Q

all values or objects have no types

A

False

18
Q

True/False: variables are not declared to have a type, they are simply assigned a value

A

True

19
Q

Text Type - str
Numeric -Types int, float, complex
Sequence -Types list, tuple, range
Mapping Type - dict
Set Types - set, frozenset
Boolean Type - bool
Binary Types - bytes, bytearray,
memoryview
None Type - NoneType

A
20
Q

a positive or negative whole number without decimals, of
unlimited length

A

int or integer

21
Q
  • a positive or negative number containing one or
    more decimals
  • can also be scientific
    numbers with an “e” to
    indicate the power of 10
A

float or floating point
number

22
Q

written with a “j” as the imaginary part

A

Complex numbers

23
Q

The String Data Type

A

String Length
Slicing Strings
Modify Strings
String Concatenation
Format Strings

24
Q

to format selected parts of a string

A

format

25
Q

to insert characters that are illegal in a string, use an _________

A

Escape Character

26
Q

________ or type conversion, convert from one data type to anothe

A

Casting

27
Q

type conversion is done automatically, without any user
involvement

A

Implicit Type Conversion

28
Q

using predefined functions that act
as a constructor of another data
type

A

Explicit Type Conversion

29
Q

− used to explain the code
− used to make the code more readable
− start with a #

A

Comments

30
Q

Python does not have a syntax for this
− to add a multiline comment, use # for each line or use a
multiline string

A

Multiline Comment