Use the string variable type when you want to store a set of characters into that variable:
- You can use the string variable type as shown in the following example:
ip_address = '10.0.0.1'
# Or you can use double quotes:
ip_address= "10.0.0.1"
#Multiple lines, using triple double quotes/single quotes
welcome_message = """ Hello there, welcome to our powerful intelligent
script, you will be amazed!"""
- To concatenate two string variables together, use the + sign:
device_name = 'Cisco Router 2911'
ip_address = '10.0.1.1'
host = device_name + ":" + ip_address
- To format a string using the % operator, do the following:
ip_address = '10.0.1.1'
host = "router IP address is : %s" % ip_address
- You can use the following formatters:
- %s: String
- %d: Integer number
- %f: Float number
- %x: Hexadecimal number