Python Flashcards

By-heart this... (47 cards)

1
Q

Modulus

A

is the remainder of the division of the left operand and the right operand,returns the decimal part (remainder) of the quotient.

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

Float

A

is a term is used in various programming languages to define a variable with a fractional value. Numbers created using a float variable declaration will have digits on both sides of a decimal point.
This is in contrast to the integer data type, which houses an integer or whole number

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

Variable

A

is a reserved memory location to store values,it gives data to the computer for processing

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

len()

A

is an inbuilt function in Python programming language that returns the length of the string.
Return Value: It returns an integer which is the length of the string.

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

format()

A

is one of the string formatting methods that which allows multiple substitutions and value formatting. This method lets us concatenate elements within a string through positional formatting.

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

Strings

A

are arrays of bytes representing Unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string

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

Dictionary

A

is a data structure that maps one value to another,kind of like how an English dictionary maps a word to its definition.
{ } are used for embedding variables

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

Boolean Strings

A

A string in Python can be tested for truth value.

The return type will be in Boolean value (True or False)

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

end= ‘ ‘

A

Python’s print() function comes with a parameter called ‘end’. By default, the value of this parameter is ‘\n’, i.e. the new line character. You can end a print statement with any character/string using this parameter.

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

Triple quotes

A

are treated as regular strings with the exception that they can span multiple lines

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

print “\”

A

Prints Backslash

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

print “'”

A

Prints Single-Quote

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

print “"”

A

Prints double quote

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

print “\a”

A

ASCII bell makes ringing the bell alert sounds

example.xterm

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

print “hello\fworld”

A

ASCII form-feed ( FF )
hello
world

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

print “hello\nworld”

A

ASCII linefeed ( LF )

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

print “\t* hello”

A

ASCII horizontal TAB

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

print u”\u041b

A

Prints 16-bit hex value Unicode character

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

print u”\U000001a9”

A

Prints 32-bit hex value Unicode character

20
Q

print “\043”

A

Prints character based on its octal value

21
Q

print “\x23”

A

Prints character based on its hex value

LinuxConfig.org

22
Q

print(“How old are you?”, end=’’)

age = input()

A

end=’’ allows to give input on the same line

23
Q

argv

A

are called features that are called “Modules” that we import like (import sys module),these are also called libraries by programmers

24
Q

print(“*” * 10)

25
Text files
In this type of file, Each line of text is terminated with a special character called EOL (End of Line), which is the new line character (‘\n’) in python by default.
26
Binary files
In this type of file, there is no terminator for a line and the data is stored after converting it into machine understandable binary language.
27
File handle
is like a cursor, which defines from where the data has to be read or written in the file. There are 6 access modes in python.
28
Read Only (‘r’)
Open text file for reading. The handle is positioned at the beginning of the file. If the file does not exists, raises I/O error. This is also the default mode in which file is opened.
29
Read and Write (‘r+’)
Open the file for reading and writing. The handle is positioned at the beginning of the file. Raises I/O error if the file does not exists.
30
Write Only (‘w’)
Open the file for writing. For existing file, the data is truncated and over-written. The handle is positioned at the beginning of the file. Creates the file if the file does not exists.
31
Write and Read (‘w+’)
Open the file for reading and writing. For existing file, data is truncated and over-written. The handle is positioned at the beginning of the file.
32
Append Only (‘a’)
Open the file for writing. The file is created if it does not exist. The handle is positioned at the end of the file. The data being written will be inserted at the end, after the existing data.
33
Append and Read (‘a+’)
Open the file for reading and writing. The file is created if it does not exist. The handle is positioned at the end of the file. The data being written will be inserted at the end, after the existing data.
34
open( )
File_object = open(r"File_Name","Access_Mode")
35
close( )
``` function closes the file and frees the memory space acquired by that file. It is used at the time when the file is no longer needed or if it is to be opened in a different file mode. File_object.close() ```
36
write( )
Inserts the string str1 in a single line in the text file. | File_object.write(str1)
37
writelines( )
For a list of string elements, each string is inserted in the text file.Used to insert multiple strings at a single time. File_object.writelines(L) for L = [str1, str2, str3]
38
read( )
Returns the read bytes in form of a string. Reads n bytes, if no n specified, reads the entire file. File_object.read([n])
39
readline( )
Reads a line of the file and returns in form of a string.For specified n, reads at most n bytes. However, does not reads more than one line, even if n exceeds the length of the line. File_object.readline([n])
40
readlines( )
Reads all the lines and return them as each line a string element in a list. File_object.readlines( )
41
truncate( )
method resizes the file to the given number of bytes. | If the size is not specified, the current position will be used.
42
*args
* asterisk takes all args to the function alike "argv"
43
int( )
function in Python and Python3 converts a number in given base to decimal.
44
Global variables
are the one that are defined and declared outside a function and we need to use them inside a function.
45
Local variable
is variable declared inside the function's body or in the local scope
46
f.seek(0)
seek() deals in bytes and not in lines... fp.seek(offset, from_what)... where fp is the file pointer you're working with; offset means how many positions you will move; from_what defines your point of reference: 0: means your reference point is the beginning of the file 1: means your reference point is the current file position 2: means your reference point is the end of the file if omitted, from_what defaults to 0.
47
+=
#The expression a += b is shorthand for a = a + b , where a and b can be numbers, or strings, or tuples, or lists (but both must be of the same type).