Python Basics: Print, Input, Variables
Python Basics: Print, Input, Variables
VARIÁVEIS---------------------------
They are spaces in the computer's memory, where - OBSERVATION -
There are two ways to place the variables within the command
One can store information. Every variable, in print.
Python language is an object. They can receive
values. When this happens, one should use the
equal symbol (=). In the first form, the variable is placed after the text in
question. Already in the second, {} is used and the structure
Example: .format(variable). Remembering that both will have the same
mensagem = “Olá mundo” result.
OPERATORS
- OBSERVATION -
a)ARITHMETIC---
5 + 2 == 7
To display the type of a variable, just use the Addition: + 5 - 2 == 3
command type before the variable.
b) Subtraction: - 5 * 2 == 10
Example:
5 / 2 == 2.5
c) Multiplication: * 5 squared equals 25
d) Division: / 5 // 2 == 2
Result: 5 % 2 == 1
e) Power or exponentiation: **
To use the '=' with
(the power can also be made) the function of equalizing,
Example:
using the pow(a,b) function, on- two must be used
of "a" represents the base and "b" “==”.
TIP
We can show information to the user in several ways.
ways, like after the information is shown 10 spaces
Result: they will be released before another piece of information is presented.
For this we will use ":10". In this way, the information will occupy
10 spaces and everything that is not a character will be added
spaces.
Example:
OBSERVATION
In the resolution, the two forms that were presented
we can fit the variables into the print command.
It is also noticeable that the results were exactly In this way, o name Gustavo plus the spaces
equals. a total of 20 spaces were accounted for and then it was presented
TIP the next information was the “!”.
Below is a table with several codes that We can use left alignments - using "<"
help verify if what was reported to the computer is after ":"Example::<20} or alignment to the right -
something like a number. What does the computer using ">" after ":". To paracentralize, just use "^" after
will return to the user True or False. :. To replace the blank spaces with something, just
Code Function put what you want after the “:”.
.isnumeric() If it is a number
Example:In this way o name will be
.isalpha() Is it literate?
centered and around it will have "=".
.isalnum() If it is alphanumeric
.isupper() If they are uppercase letters
.islower() If they are lowercase letters
.isspace() It is a space - TIP -
.isttle( ) It is capitalized To define the number of decimal places, just use the
Example: following expression:
In this way, using {:.3f} the number will have 3 decimal places.
TIP
So that there is no line break between
print commands, just use 'end=' ' ' at the end of
command.
.
In this way, the results of the print commands will be
displayed on different lines.
MODULES--------------------------
--add a module in Python, one must
To
use the command 'import' followed by the name of the