THE Python Triton

Welcome to Python.Triton Tutorials!!!

On this page, all you need to do is to click on one of the tabs and it will open an entire new world.


Print Function

The print function is one of the most important funcitons in Python coding as it allows the code to interpret what the outcome is of the coding. A simple example of using the print funciton is the following:

print('Hello World!')

Hello World!

As you can see, the print function is at the start of the line of code interpreting all the strings within its bracket. A simple rul must be applied though, if the printing string is a set of text, like the example above, it must be enclosed with either a single (') or double (") quote. Note it cannot be a mixture of the two quotes enclosing the same text. However, if the printing string is a variable, then no quotation marks are needed.

print("Hello World')

File "program.py", line 1

print("hello')

SyntaxError: EOL while scanning string literal

---------------------------------------------------------------------------

msg='123'

print(msg)

123

In Print Function, you will be taught the basic uses of printing strings and variables that can be done with Python, please visit Printing on Grok, for more info.

Input Function

The input function allows us to ask the user for information. This function is used to make the user deinfe a variable within the coding, for example, if the program asked for the user's name, the program will look similar to this.

name = input('What is your name? ')

print(name)

Causing the program to allow the user to type in their answer, the print that answer as the result of the program.

The input function is able to be used for mutliple questions for information from the user. However, if the code requires a number from the user to be entered, then the prorgam will require a function of 'int' between the variable name and the input function, but not alongside the print function, as shown below.

age = int(input('What is your age? '))

print(age)

In Input Function, you will be taught the basic uses of input messaging and user input that can be done with Python, please visit Reading user input on Grok, for more info.

Decision Making

[Insert Here]

In Decision Making, you will be taught the basic uses of control structures that can be done with Python, please visit Making Decisions on Grok, for more info.

Calculation Function

Python can function as a powerful calculator.

For example, to calculate (or evaluate) the number of seconds in a leap year, you could type:

print((365 + 1)*24*60*60)

SIGNS

Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Divison
** To the power of

In Calculation Function, you will be taught the basic uses of calculations that can be done with Python, please visit Calculation Function on Grok, for more info.

Changing Text Case Function

Manipulating strings allows us to change the string's letter case to switch between uppercase and lowercase, we use mthods in what we call string methods.

A method is a bit of code that allows modification of a string, in the below example, we are able to switch between case byb adding the 'lower() or 'upper()' operators.

msg = "I know my ABC"

print(msg.lower())

print(msg.upper())

We are also able to test whether the case of a string is either/or. To do this we either code the 'isupper' or 'islower' operators, resulting in the printing of either True or False as shown below.

msg = "dogs go woof!"

print(msg.islower())

print(msg.isupper())

TRUE

FALSE

In Changing Text Case Function, you will be taught the basic uses of changing the case of text that can be done with Python, please visit Changing Text Case on Grok, for more info.

Length Function

In python, you have the ability to find the total length of a string, to do this, you can just add 'len' between the print command and the string to show how many characters are contained within that string. For example,

print(len('Hello World!'))

12

See how the length function counted all the character including the letters, punctation and the space between words.

In Length Function, you will be taught the basic uses of investigating strings that can be done with Python, please visit Investigating Strings on Grok, for more info.

String Within Strings Function

Here, you can learn how to manipulate certain strings within other strings. With this coding, you are able to check the contents of a string to test whether it contains a particular character/s or not, to achieve this, we need to code either the 'in operator or the 'not in' into the program, for example.

msg = 'hello world'

print('h' in msg)

print('x' in msg)

TRUE

FALSE

---------------------------------------------------------------------------

msg = 'concatenation is fun'

print('cat' not in msg)

print('dog' not in msg)

FALSE

TRUE

In Strings Within Strings Function, you will be taught the basic uses of finding, moving and replacing strings within other strings that can be done with Python, please visit Manipulating Strings on Grok, for more info.

Replacement Function

The replacement function allows you to replace part of a string, known as a substring, with another substring. This function requires the coding for the substring to be replaced and the substring in which is replacing another. The program for this should be similar to the following:

Msg = ‘Hello world’

Print(msg.replace(‘l’. ‘X’)

Here, all the substrings ‘l’ within the whole string will be replaced with the substring ‘x’, to produce an outcome of:

HeXXo worXd

It is possible to replace multiple strings in one program, however, you must begin with the larger substring replacement first and the shortest substring replacement last for all replacement to correctly work, or some of the replacements might not occur as they won’t be present. For example:

Msg = ‘Hello world’

Msg = msg.replace(‘o’, ‘X’)

Msg = msg.replace(‘Hello’, ‘goodbye’)

Print(msg)

With the outcome resulting in --> HellX wXrld --> as after the first replacement, there was not hello present.

In Replacement Function, you will be taught the basic uses of replacing strings that can be done with Python, please visit Replacing Parts of Strings on Grok, for more info.

Lists and Loops Function

[INSERT HERE]