Codice: Seleziona tutto
comand = input("Enter the comand: ")
if comand == "cd *":
print("Hello")
Cosa dovrei fare o usare per sostituire quell'asterisco?
Codice: Seleziona tutto
comand = input("Enter the comand: ")
if comand == "cd *":
print("Hello")
Codice: Seleziona tutto
import re
comand = input("Enter the comand: ")
if re.match(r"cd .*", comand):
print("Hello")
Codice: Seleziona tutto
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>> command = input('Enter the command: ')
Enter the command: cd *
>>> if command == 'cd *':
print('Hello')
else:
print('No Hello')
Hello
>>>
Tanto per cambiare, non l'avevo compreso, comunque :
Codice: Seleziona tutto
>>> command = input('Enter the command: ')
Enter the command: cd ~/
>>> if command[:3] == 'cd ':
print('Hello')
else:
print('No Hello')
Hello
>>> command = input('Enter the command: ')
Enter the command: ls Documenti
>>> if command[:3] == 'cd ':
print('Hello')
else:
print('No Hello')
No Hello
>>>
Codice: Seleziona tutto
if command[:3] == 'cd ':
Visualizzano questa sezione: 0 utenti iscritti e 12 ospiti