Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with python variables and raw_input
#1
I there a way I can do something like:
raw_input("Say something: ")
The person would then type:
Hello
Is there a way to make
x= the first letter(in this case h)
y= the second letter(in this case e)
And so on...?
Reply
#2
Yes
try

Code:
t = raw_input("Type: ")
print t[0]
Reply
#3
Yep the string slices:

x = raw_input('Say something: ')

Then we have variable x with string 'Hello'.

Code:
print x[0:1]
'H'
Code:
print x[1:2]
'e'
Code:
print x [2:3]
'l'

If you then want variable y to be the second letter:

Code:
y = x[1:2]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 2,009 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 9,215 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,670 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 904 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 852 02-07-2010, 03:55 PM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 2 Guest(s)