how to turn a string from lower case to uppercase
print(Variable.upper())
how to turn a string from upper case to lower case
print(Variable.lower())
how to turn a string to have title case
print(Variable.title())
command to count the number of characters in a string
print(len(Variable))
how to extract a substring from a large string from a sequence of characters
print(Variable[3:5])
how to concatenate two or more strings
variable = variable1 + variable2
how to open a file
file = open(“fruit.txt”,”r”)
how to close a file
file.close()
How to read a line in a file
file.readline()
how to write a line in a file
file.write(“oranges”)
how to create a new file
file = open(“shopping.txt”,”w”)
how to append a file
file = open(“shopping.txt”,”a”)
how to perform an SQL query
SELECT (what to return)
FROM (specifies the table name to retrieve data from)
WHERE (filters the data based on a specific condition)
how to create a 1D array
scores = [0]*5
creates an array with 5 elements, each initialised to 0
how to create a 2D array
players = [[None]*3 for _ in range(3)]
creates a 3x3 2D array with all values set to None
how to assign a value to a 2D array
players [0][1] = “Holly”
replaces text in row 0, column 1 with “Holly”
how to create a populated 2D array
players = [[“Rob”,”Paul”,”Hayley”], [10, 5, 8]]
how to access a value in a 2D array
value = players[2][2]
retrieves the value at row 2, column 2
how to create a function
def squared(number):
squared = number^2
return squared
how to generate a random number
import random
number = random.randint(1,10)