After running that script, you will see the following message on your screen:
This is an awesome variable.
Important Note: Python can choose the right type of variable on your behalf. You don’t
have to declare the variable before setting its value.
Functions
The Python language comes with preinstalled functions. Kali Linux has an extensive
collection of functions, although you may download more from online libraries. Here are
some functions that you’ll use in your programs:
int() – Use this function to truncate numeric data. It simply gives the integer part of
the argument.
len() – This function counts the items in a list.
exit() – This function lets you exit a program.
max() – With this function, you can determine the highest value of a list.
type() – Use this function to identify the data type of a Python object.
float() – This function converts its argument into a floating-point numeral.
sorted() – Use this function to sort the entries of a list.
range() – This function gives a list of numbers between two specific values. You
need to set the said values as the function’s arguments.
Lists
Most programming languages use arrays. An array is a collection of different objects. You
may retrieve an entry from an array by specifying the position of the former. For example,
you can get the fourth value of an array by typing [4]. Python has a similar feature, but it
is known as “list”.
Python lists are “iterable”. That means you can use them for your loop statements (you’ll
learn more about loops later). Let’s assume that you want to retrieve the third element of
the “SampleList” (i.e. the one you created earlier). Here are the things that you should do:
1. Type the word “print”. This command allows you to display information.
2. Specify the name of the list (i.e. SampleList).
3. Add a pair of brackets.
Précédent

- 22/94

Suivant