Chapter 3 - Glossary Flashcards

1
Q

Function

A

Function is a named sequence of statements that
performs a computation. When you define a function, you specify the name and the
sequence of statements.

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

Functions that convert values from one type to another.

A

int()
str()
float

>>> int('32')
32
>>> float(32)
32.0
>>> str(32)
'32

int can convert floating-point values to integers, but it doesn’t round off; it chops off
the fraction part:»> int(3.99999)
3

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

What is module ?

A
A module is a file that contains a collection of related functions.Before we can use the functions in a module, we have to import it with an import
statement:
>>> import math
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to use modules

A
The module object contains the functions and variables defined in the module. To access one of the functions, you have to specify the name of the module and the name of the function, separated by a dot (also known as a period). This format is called dot
notation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to get value of pie

A

import math
pie = math.pi
print(f”Value of Pie - {pie:,.2f}”)

Value of Pie - 3.14

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

How many indentations win function body

A

Four Spaces.

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

How to define a function ?

A

The first line of the function definition is called the header; the rest is called the body. The header has to end with a colon and the body has to be indented. By con‐vention, indentation is always four spaces. The body can contain any number of state‐ments.

def  printName(): # Function Header
    print("Sundy")   # Function Body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Function Defination on Interactive Mode ?

A

If you type a function definition in interactive mode, the interpreter prints dots (…) to let you know that the definition isn’t complete:
»> def print_lyrics():
… print(“I’m a lumberjack, and I’m okay.”)
… print(“I sleep all night and I work all day.”)

To end the function, you have to enter an empty line.

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

What is created when a function is defined ()

A

Defining a function creates a function object, which has type function:

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

How to read a Program .

A

when you read a program, you don’t always want to read from top to
bottom. Sometimes it makes more sense if you follow the flow of execution.

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

What is traceback ?

A

This list of functions is called a traceback. It tells you what program file the error occurred in, and what line, and what functions were executing at the time. It also
shows the line of code that caused the error.

NameError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18764/1435530308.py in 
      5     print(value)
      6 printTwice(math.pi)
----> 7 print(value)

NameError: name ‘value’ is not defined

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

What happen ,when you call a function in interactive mode.

A

Python displays the result:
»> math.sqrt(5)
2.2360679774997898

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

What are Fruitful and Void Functions

A

Inbuit Functions,for lack of a better name, I call them fruitful functions.
Functions don’t return a value. They are called void func‐
tions.

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

What is none type value.

A

Void function returns None value

The value None is not the same as the string ‘None’. It is a special value that has its

own type:
»> print(type(None))

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