C859 Python Syntax

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/82

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

83 Terms

1
New cards

var1, var2, var3 = 1, 2, 3

multiple variable assignment

2
New cards

12

integer

3
New cards

1.2

float

4
New cards

'twelve'

string

5
New cards

"twelve"

string

6
New cards

True or False

Boolean value

7
New cards

type()

determines type of an object (integer, boolean, etc)

8
New cards

int()

converts to integer object

9
New cards

float()

converts to float object

10
New cards

str()

converts to string object

11
New cards

print()

displays a message

12
New cards

+

addition (integer) or concatenation (string)

13
New cards

-

subtraction

14
New cards

**

power of

15
New cards

%

modulus, remainder

16
New cards

/

division, always results in float

17
New cards

//

division, always results in integer

18
New cards

=

assignment operator

19
New cards

+=

reassignment operator, adds

20
New cards

-=

reassignment operator, subtracts

21
New cards

*=

reassignment operator, multiples

22
New cards

/=

reassignment operator, divides

23
New cards

<

less than

24
New cards

>

greater than

25
New cards

<=

less than or equal to

26
New cards

>=

greater than or equal to

27
New cards

==

equal to

28
New cards

!=

not equal to

29
New cards

len()

returns length

30
New cards

title()

capitalizes first letter of each word

31
New cards

islower()

determines if the string consists of lowercase characters

32
New cards

count()

totals number of times an argument is found within a predefined value

33
New cards

format()

inserts variable data in a string

34
New cards

def

keyword used to create functions

35
New cards

def myfunction():

syntax for function declaration

36
New cards

return

defines output of a function

37
New cards

if age < 16:

creates an if statement

38
New cards

else:

else statement, used in conjunction with if statement or if/elif statement

39
New cards

elif age >= 16 and age <= 18:

elif statement, used in conjunction with if statement

40
New cards

True and False

False: and operation will always be false unless both sides are true

41
New cards

True or False

True: or operation will always be true unless both sides are false

42
New cards

not(True and False)

True: Boolean not operation will produce the inverse value.

43
New cards

myNumbers = [1, 4.8, 7, 9.2, 3, 0]

creates a list

44
New cards

mylist[0]

accesses first element from a list

45
New cards

mylist[-1]

accesses last element from a list

46
New cards

mylist[1:3]

slices list including second and third element

47
New cards

mylist[:3]

slices list beginning with first element and including through the third element. Index position 3 is not included in selection.

48
New cards

mylist[3:]

slices list beginning with fourth element and include remainder of the list

49
New cards

9.2 in myNumbers

looks for a match and returns Boolean value

50
New cards

9.2 not in myNumbers

ensures a match does not exist in list

51
New cards

len()

counts items in list

52
New cards

max()

returns greatest element of list

53
New cards

min()

returns smallest element of list

54
New cards

sorted()

returns copy of list ordered smallest to largest

55
New cards

sorted(listname, reverse=True)

returns copy of list ordered largest to smallest

56
New cards

sum()

returns total sum of list values

57
New cards

append()

adds new value to end of list

58
New cards

pop()

removes last item from a list

59
New cards

pop(1)

removes second item from a list

60
New cards

join()

joins values from a list using a defined separator

61
New cards

set()

creates a set, or a list that contains unique items

62
New cards

add()

adds value to set

63
New cards

discard()

removes value from set, if found

64
New cards

for city in cities:

iterates over items within a list

65
New cards

range()

defines a range of numbers

66
New cards

while temp >= 32:

iterates a set of commands as long as the condition remains true, stopping when the condition becomes false

67
New cards

break

loop command that stops iteration prematurely

68
New cards

studentGrades = { 'Orfu': 83, 'Bismark': 98, 'Igor': 72}

entries are added in key/value pairs

69
New cards

if 'key' in dictionary:

verifies if key exists in dictionary

70
New cards

get()

looks up value by key

71
New cards

myPhone = (877, 435, 7948)

creates a tuple

72
New cards

open('/my_path/my_file.txt','r')

opens a file object for reading

73
New cards

open('/my_path/my_file.txt','w')

opens a file object for writing

74
New cards

read()

reads data from open file

75
New cards

close()

closes open file

76
New cards

write()

writes to open file

77
New cards

with open('/my_path/my_file.txt','r') as f:

opens a file, performs operations and automatically closes file

78
New cards

import math

imports math module

79
New cards

from collections import defaultdict

imports individual function from a module

80
New cards

from csv import reader as scvreader

mports individual function from a module and assigns it a new name

81
New cards

$ pip3 install pytz

install package through the command line

82
New cards

import pytz

imports a package

83
New cards

split()

string method used to break apart a string and return a list