Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Accessing Values in Strings in python

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 350
    Comment on it

    Python does not support a character type treated as strings of length 1, thus also consider a substring. To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring.
    For example

    #!/usr/bin/python
    
    var1 = 'Hello World!'
    var2 = "Python Programming"
    
    print "var1[0]: ", var1[0]
    print "var2[1:5]: ", var2[1:5]
    

    When the above code is executed, it produces the following result

    var1[0]:  H
    var2[1:5]:  ytho

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: