knowt logo

Python

Humans use code to give instructions to machines.

print ("Hello World")

Prints Hello World to the console by sending a message to it. Without the quotation marks, the computer won’t understand your instructions. However, numbers don’t need quotation marks.

The print() function displays a message to the screen. This is the easiest way to send a value to the screen.

The print() function can also directly send math operations to the screen.

item = 'watch'

Variables are used to remember certain information so that it can easily be accessed. They have a name and a value which are connected by an equals sign. In the code above, item is the name and watch is the value. The code below shows how to print the variable shown in the previous code, this is called calling a variable. Math Operations can be done in variables. Reassigning, or updating, a variable will change its value and forget the previous value. Variable names cannot have spaces or start with numbers.

print(item)

Using the print function requires parenthesis but declaring variables don’t!

A piece of text data is called a string. These need to be surrounded by quotation marks. Single or double quotation marks can be used as long as they match.

Numerical data (numbers) don’t need quotation marks.

Code is made of statements, which are the instructions for a computer to follow.

Math Operations: + add, - subtract, * multiply, / divide.

Writing code in a program is the process of 1) Writing 2) Running (executing) 3) Debugging (Fixing errors).

Errors in code are known as bugs. The first bug that is seen in the code will stop further execution, because code is executed line by line from top to bottom.

Comments can be added to the code with the #. This helps you and other readers of the code to easily understand what the code is saying. Comments are just for humans and are ignored by computers. Comments can also be used to temporarily disable a line.

Python is case sensitive which means that the lowercase and the uppercase of each letter are seen as different.

Snake case is a name for a way of declaring variables using _ (underscores) to separate words (because a variable name can’t have spaces in it). This is good for declaring variable names that have multiple words.

address=input()

You can use the input() function while declaring a variable so that the screen will ask the user for an input and store value in a variable. An example is shown above.

In Python, there are different data types for numbers (both positive and negative). The data types are integers and floats. Integers are whole numbers, and floats include decimals (if an integer is put in as a float and printed, it will be printed as a decimal). If numbers are put between quotation marks, they will be treated as a string (as anything inside quotations marks will) and will not be able to be used in calculations. The division of two numbers also produces a float even if the actual value is an integer (a .0 gets added to the end).

a="basket"
b="ball"
print (a+b)
#prints basketball

print ("Hello" + " world")
#prints Hello world

Concatenation is joining together string values using the + sign as the two examples shown above.

balance = "780"
type(balance)

Python handles different types of data, data types, differently. To check what the data type of a value is, you can use the type() function as shown above.

K

Python

Humans use code to give instructions to machines.

print ("Hello World")

Prints Hello World to the console by sending a message to it. Without the quotation marks, the computer won’t understand your instructions. However, numbers don’t need quotation marks.

The print() function displays a message to the screen. This is the easiest way to send a value to the screen.

The print() function can also directly send math operations to the screen.

item = 'watch'

Variables are used to remember certain information so that it can easily be accessed. They have a name and a value which are connected by an equals sign. In the code above, item is the name and watch is the value. The code below shows how to print the variable shown in the previous code, this is called calling a variable. Math Operations can be done in variables. Reassigning, or updating, a variable will change its value and forget the previous value. Variable names cannot have spaces or start with numbers.

print(item)

Using the print function requires parenthesis but declaring variables don’t!

A piece of text data is called a string. These need to be surrounded by quotation marks. Single or double quotation marks can be used as long as they match.

Numerical data (numbers) don’t need quotation marks.

Code is made of statements, which are the instructions for a computer to follow.

Math Operations: + add, - subtract, * multiply, / divide.

Writing code in a program is the process of 1) Writing 2) Running (executing) 3) Debugging (Fixing errors).

Errors in code are known as bugs. The first bug that is seen in the code will stop further execution, because code is executed line by line from top to bottom.

Comments can be added to the code with the #. This helps you and other readers of the code to easily understand what the code is saying. Comments are just for humans and are ignored by computers. Comments can also be used to temporarily disable a line.

Python is case sensitive which means that the lowercase and the uppercase of each letter are seen as different.

Snake case is a name for a way of declaring variables using _ (underscores) to separate words (because a variable name can’t have spaces in it). This is good for declaring variable names that have multiple words.

address=input()

You can use the input() function while declaring a variable so that the screen will ask the user for an input and store value in a variable. An example is shown above.

In Python, there are different data types for numbers (both positive and negative). The data types are integers and floats. Integers are whole numbers, and floats include decimals (if an integer is put in as a float and printed, it will be printed as a decimal). If numbers are put between quotation marks, they will be treated as a string (as anything inside quotations marks will) and will not be able to be used in calculations. The division of two numbers also produces a float even if the actual value is an integer (a .0 gets added to the end).

a="basket"
b="ball"
print (a+b)
#prints basketball

print ("Hello" + " world")
#prints Hello world

Concatenation is joining together string values using the + sign as the two examples shown above.

balance = "780"
type(balance)

Python handles different types of data, data types, differently. To check what the data type of a value is, you can use the type() function as shown above.