WGU Python D522
Print(10 > 9)
print(10 == 9)
print (10 < 9)
Boolean
Print(bool("hello"))
print(bool("15"))
print(bool(x))
Boolean examples of true
Print(bool(false))
print( )
print(0)
Boolean examples of false
Print(isinstance(x, int))
Determine if an object is of a certain data type
Int( )
Casts an integer from an integer literal, float literal, or string literal
Float( )
Casts a float from an integer literal, a float literal, or a string literal
Str( )
Casts a string from strings, integer literals, or a float literals
Print("text")
Outputs text to the console
Print("text", end=" ")
print("more text")
Will end with a space and continue on the same line ("text more text")
Print("wage", wage)
Comma will print both items with a space between them
Print(variable)
Prints the value of the variable
Print("1\n2\n3")
Print using newline characters
Print( )
Print a blank line
Python file.py
Run a script file
Random function
WGU
, WGU
There is no random function, but there is a random module
(import random)
For x in "bananas":
print(x)
Strings are arrays, so this will loop through the characters in "bananas"
Variable=input( )
Assign text entered by the user to a variable; input is always a string
Variable = int(input)
Convert user input into an integer
Hourly_wage = int(input("enter hourly wage: "))
Display text prompt (enter hourly wage) to request input from user and convert to
integer
Print(a.upper( ))
Display a in console in upper case
Print(a.lower( ))
Display a in console as lower case
Print(a.strip( ))
Remove whitespace at beginning and end
Print(a.replace("h", "j"))
Replace a string with another string
Print(a.split("b"))
Split string at specified character
C=a+b
print(c)
Concatenate (combine) two strings
A=(f"my name is john, i am {age}")
print(a)
F-string; { } is the placeholder/modifier
A = 85.8756
b = format(a, ".2f")
print(b)
Modifier to format the value to 2 decimal places (85.88)
Price = 85.87562649
b = f"price: ${price:.2f}"
print(b)
F-string with placeholder for price and modifier to format value to 2 decimal places
(price: $85.88)
What built-in data type is used when you assign text to your variable?
WGU