Variables

Variables are used in Python and in other programming languages to store temporary values in memory in order to reuse them in multiple places in the source code.

We have various types of variables in Python, as shown in the following list:

  • Strings
  • Numbers
  • Lists
  • Dictionaries
  • Tuples

At any stage in your source code, you can cast from one variable to another using the following type casting syntaxes:

# A string type port number
port_number = "80"

# An integer, which holds the number of hosts
host_count = 254

# Convert port number into integer type
int(port_number)

# Convert port number into a float type with decimals
float(port_number)

# Convert the number of host into a string
str(host_count)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.27.202