[英]How can i make two numbers 9 and 3 as special Number in Python?
I am creating a simple function to check the special character in Python.我正在创建一个简单的 function 来检查 Python 中的特殊字符。 We make a Python Program to check if a string contains any special character.我们编写了一个 Python 程序来检查字符串是否包含任何特殊字符。
import re
def run(string):
regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
if(regex.search(string) == None):
print("String value is accepted")
else:
print("String value is not accepted.")
if __name__ == '__main__' :
# Here in "money@rupay" the @ is a special character.
string = "money@rupay"
run(string)
# The Output is:- String value is not accepted.
In function, I check the special characters [@_?#$%^&*()<>:/\|}{~:]
reject as String.在 function 中,我检查了特殊字符[@_?#$%^&*()<>:/\|}{~:]
作为字符串拒绝。 It works perfectly.它完美地工作。
What is the way to pass special numbers as the restricted number in python?在 python 中将特殊号码作为限制号码传递的方法是什么? I want to pass some number as a special number in python like- 9
and 3
.我想在 python 中传递一些数字作为特殊数字,例如9
和3
。 How can I make 9 and 3
as a special number which is restricted in the python program?如何将9 and 3
作为 python 程序中限制的特殊数字?
Just put 9
and 3
into brackets in your regex pattern:只需将9
和3
放入正则表达式模式的括号中:
import re
def run(string):
regex = re.compile('[@_!#$%^&*()<>?/\|}{~:93]')
if(regex.search(string) == None):
print("String value is accepted")
else:
print("String value is not accepted.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.