basics Flashcards
(33 cards)
int
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
float
Float, or “floating point number” is a number, positive or negative, containing one or more decimals.
complex
Complex numbers are written with a “j” as the imaginary part.
string
String literals in python are surrounded by either single quotation marks, or double quotation marks.
Cast as string
str()
Cast as int
int()
Cast as float
float()
Cast as complex
complex()
Addition
+
Subtraction
-
Multiplication
*
Division
/
Modulus
%
Exponentiation
**
Floor division
//
and
Returns True if both statements are true
x < 5 and x < 10
or
Returns True if one of the statements is true
x < 5 or x < 4
not
Reverse the result, returns False if the result is true
not(x < 5 and x < 10)
is
Returns true if both variables are the same object
x is y
is not
Returns true if both variables are not the same object
x is not y
List
is a collection which is ordered and changeable. Allows duplicate members.
A list is a collection which is ordered and changeable. In Python lists are written with square brackets.
thislist = [“apple”, “banana”, “cherry”]
Tuple
is a collection which is ordered and unchangeable. Allows duplicate members.
A tuple is a collection which is ordered and unchangeable. In Python tuples are written with round brackets.
thistuple = (“apple”, “banana”, “cherry”)
Set
is a collection which is unordered and unindexed. No duplicate members.
A set is a collection which is unordered and unindexed. In Python sets are written with curly brackets.
thisset = {“apple”, “banana”, “cherry”}
Dictionary
is a collection which is unordered, changeable and indexed. No duplicate members.
A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.
thisdict = {
“brand”: “Ford”,
“model”: “Mustang”,
“year”: 1964
}