Snakify Python Notes: Basics
Note*: Most of these notes are for software called "Snakify" which helps you learn Python Code.*
print() is used to output data in Python
input() We use this function to input data into a program. It reads a single line of text, as a String unless specifically specified with other code.
# Words that come after this will be ignored when you run the code. They are called comment(s).
int() this transforms strings into integers,
int(input() this transforms ***input ***strings into integers
str transforms integers to strings
sep = used to combine strings together
+ used to combine strings
end = By default, each print statement ends with a new line. With the end function, we can change that to end with a space instead to increase readability in an IDE window.
Can be used as multiplication/exponentiation (see math)
Can be used with strings and integers to repeat string segments
Example
Input :
Output
When writing a complex program, you usually can't print the answer to your calculation right away. Instead, you use variables to store intermediate results.
The name can be any string of Latin characters mixed with numbers and the underscore _ but cannot start with a number. So, much3q1 is a valid name for a variable, and 2pac is not. The variable can also start with an underscore _
*The assignment operator is =. This can define a variable
Eg. a = 3 #a is the variable and 3 is the value of a
The more variables you introduce, and the more logical the names are, the more readable your code will be.
A string is a set of characters that a program interprets as a word
doesn't matter what quotation marks will you use to define a string: these ' ' or these " "
Check example for more information
You can turn an integer into a string with str
Some keys cannot be typed directly into a string variable, such as the “tab” or “enter” keys.
In order to print these keys, we need an “escape character” in the text to tell python that the next character to be interpreted is something different than the regular text.
In python, the escape character is a backslash, “\”, which is then immediately followed by a single character.
This is useful so that we can also print characters such as quotes without python interpreting that quote ending the string we want printed.
Here are some examples including printing a new line, a tab, quotes, or even to print the backslash itself.
Input
print(“Hi.\nA new line with \\n.”)
print(“Quotes \’ and \” are easy as well!”)
Output
Hi.
A new line with \n.
Quotes ‘ and “ are easy as well!
print(5 + 10) #the plus sign (+) represents addition
print(3 * 7, (17 - 2) * 8) #the asterisk (*) represents multiplication, the minus sign (-) represents subtraction. The comma (,) represents that the 2 equations are separate
#NOTE: during output, the comma will disappear and show 2 answers with a space in between ((eg. 21 120) >>> answers for the question above)
print(2 ** 16) # two stars are used for exponentiation (2 to the power of 16)
print(37 / 3) # single forward slash is a division
print(37 // 3) # double forward slash is an integer division
# it returns only the quotient of the division (i.e. no remainder)
print(37 % 3) # percent sign is a modulus operator
# it gives the remainder of the left value divided by the right
Note*: Most of these notes are for software called "Snakify" which helps you learn Python Code.*
print() is used to output data in Python
input() We use this function to input data into a program. It reads a single line of text, as a String unless specifically specified with other code.
# Words that come after this will be ignored when you run the code. They are called comment(s).
int() this transforms strings into integers,
int(input() this transforms ***input ***strings into integers
str transforms integers to strings
sep = used to combine strings together
+ used to combine strings
end = By default, each print statement ends with a new line. With the end function, we can change that to end with a space instead to increase readability in an IDE window.
Can be used as multiplication/exponentiation (see math)
Can be used with strings and integers to repeat string segments
Example
Input :
Output
When writing a complex program, you usually can't print the answer to your calculation right away. Instead, you use variables to store intermediate results.
The name can be any string of Latin characters mixed with numbers and the underscore _ but cannot start with a number. So, much3q1 is a valid name for a variable, and 2pac is not. The variable can also start with an underscore _
*The assignment operator is =. This can define a variable
Eg. a = 3 #a is the variable and 3 is the value of a
The more variables you introduce, and the more logical the names are, the more readable your code will be.
A string is a set of characters that a program interprets as a word
doesn't matter what quotation marks will you use to define a string: these ' ' or these " "
Check example for more information
You can turn an integer into a string with str
Some keys cannot be typed directly into a string variable, such as the “tab” or “enter” keys.
In order to print these keys, we need an “escape character” in the text to tell python that the next character to be interpreted is something different than the regular text.
In python, the escape character is a backslash, “\”, which is then immediately followed by a single character.
This is useful so that we can also print characters such as quotes without python interpreting that quote ending the string we want printed.
Here are some examples including printing a new line, a tab, quotes, or even to print the backslash itself.
Input
print(“Hi.\nA new line with \\n.”)
print(“Quotes \’ and \” are easy as well!”)
Output
Hi.
A new line with \n.
Quotes ‘ and “ are easy as well!
print(5 + 10) #the plus sign (+) represents addition
print(3 * 7, (17 - 2) * 8) #the asterisk (*) represents multiplication, the minus sign (-) represents subtraction. The comma (,) represents that the 2 equations are separate
#NOTE: during output, the comma will disappear and show 2 answers with a space in between ((eg. 21 120) >>> answers for the question above)
print(2 ** 16) # two stars are used for exponentiation (2 to the power of 16)
print(37 / 3) # single forward slash is a division
print(37 // 3) # double forward slash is an integer division
# it returns only the quotient of the division (i.e. no remainder)
print(37 % 3) # percent sign is a modulus operator
# it gives the remainder of the left value divided by the right