Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to give a pattern to my strings in a python script.
I mean something like this:
x = "hello" + anyString
Note: this anyStringcan be anything even nothing
Update:
at this code, I want to type anything at the end of the string and get the same result
userCommand = input("you> ")
if userCommand == "hello":
print("hi!")
result:
you> hello
hi!
i want to get same result when i type anything else after hello something like this:hello!
userCommand = input("you> ")
if userCommand.startswith("hello"):
print("hi!")
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to right a function that can recognize integers in a string. I'm new to python so I'm sorry if its a simple question. Previously I have used statements like
if he in hello:
I'm wondering if there's something similar to this but instead of it being "he" or whatever it could be a number. Thanks for any help!
One way could be that you convert the number to a string?
num = 5;
numString = "This string has 5 in it"
if str(num) in numString:
print("Yay")
else:
print("Nah")
You can convert the integer to a string:
my_int = 123
my_str = "98483123994"
if str(my_int) in my_str:
print("YES!")
else:
print("NO!")
Does that work for your case?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
answer=input(print('What s the capital',country,'?'))
RETURN
What s the capital of South Africa ?
None
And I have to put my answer just after the 'none'
You are printing inside the input function and print returns None.
You should do something like this:
country = "Italy"
answer = input(f"What's the capital of {country}? ")
print(answer)
Read the documentation here.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to get what I want? For example, I have a string like this
'RC00001 C00003_C00004RC00087 C00756_C01545RC01045 C06756_C03485'
I want to get
'RC00001 C00003_C00004','RC00087 C00756_C01545','RC01045 C06756_C03485'
What should I do? I have tried many times, but I failed. Please help me! Thank you!
answer=[]
a="RC00001 C00003_C00004RC00087 C00756_C01545RC01045 C06756_C03485"
b = a.split("RC")
for i in b[1:]:
answer.append("RC%s" % (i))
print(answer)
This will output:
['RC00001 C00003_C00004', 'RC00087 C00756_C01545', 'RC01045 C06756_C03485']
If you want to achieve this using regex, you could try the following
import re
input_str = 'RC00001 C00003_C00004RC00087 C00756_C01545RC01045 C06756_C03485'
pattern = '(RC[\d+]+\s+C[\d]+_C[\d]+)'
print(re.findall(pattern, input_str))
# output
# [('RC00001 C00003_C00004', 'RC00087 C00756_C01545', 'RC01045 C06756_C03485')]
provided the format is always RC{numbers} C{numbers}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
name = input("What is your name?")
if name = Bob:
print ("Hi")
I am a beginner in python so it would be greatly appreciated if you would give an explanation or simple answer
-thanks
if name == "Bob":
print ("Hi")
Use == for comparison, and string variables should be within quotes:
if name == "Bob":
print ("Hi")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
a = 0
if (a==0):
print "a==0"
print "hello"
I have many code where the print "hello" is, and I can't put an else and just TAB everything. Is there anything that can stop executing the function or something?
In Python programs, it's much better to use spaces to tabs. If you can, configure your IDE to do this. The parenthesis surrounding (a==0) are superfluous.
a= 0
if a == 0 :
print "a==0"
print "hello"
The quickest way to stop a function's execution is instruction return .