Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with slicing string
#1
Can you help me figure out what is the issue in the below code.

My Code:

email = input("What is your email add: ")
#UN = email[:email.index("@")]
print(email)
Error:
>>> ================================ RESTART ================================
>>> 
What is your email add: asdasdasdasdasdasd


Error:
Traceback (most recent call last):   File "C:/Users/ykarkera/Desktop/Python Bible/Strings.py", line 1, in <module>     email = input("What is your email add: ")   File "<string>", line 1, in <module> NameError: name 'asdasdasdasdasdasd' is not defined
>>>
Reply
#2
Use raw_input() instead of input()
Python 2 ?

Python 2 see the input() returns as a valid Python statement/code. So there is no variable called 'asdasdasdasdasdasd' and you get an error.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Yes 2.7 version.

raw_input worked. Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  f string concatenation problem growSeb 3 407 Jun-28-2021, 05:00 AM
Last Post: buran
Question Problem with string and \n Falassion 6 520 Jun-15-2021, 03:59 PM
Last Post: Falassion
  how to deal with problem of converting string to int usthbstar 1 571 Jan-05-2021, 01:33 PM
Last Post: perfringo
  string problem Mathisdlg 6 1,185 Aug-05-2020, 09:31 AM
Last Post: Mathisdlg
  String slicing and loop iteration divyansh 9 2,000 Jun-07-2020, 10:29 PM
Last Post: divyansh
  String slicing divyansh 6 1,187 May-31-2020, 06:15 AM
Last Post: pyzyx3qwerty
  sequence slicing problem qliu 4 772 Apr-27-2020, 09:50 PM
Last Post: deanhystad
  string slicing help oli_action 2 819 Mar-22-2020, 09:57 AM
Last Post: oli_action
  Unicode string index problem luoheng 6 1,150 Nov-23-2019, 03:04 PM
Last Post: luoheng
  Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy) Drone4four 4 1,270 Aug-23-2019, 07:59 PM
Last Post: Drone4four

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020