简体   繁体   English

如何在 Python 中将两个数字 9 和 3 作为特殊数字?

[英]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 中传递一些数字作为特殊数字,例如93 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:只需将93放入正则表达式模式的括号中:

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.

相关问题 如何在 python tkinter 中的两个输入字段编号之间创建一个随机数? - How can I create a random number between two entry field numbers in python tkinter? 如何使用 Python 将两个 arrays 与特殊参数结合起来 - How can I combine two arrays with special parameters using Python 如何检查素因数列表以确定原始数字是否可以表示为 Python 中两个 3 位数字的乘积? - How do I check a list of prime factors to determine if the original number can be expressed the product of two 3-digit numbers, in Python? 如何根据 python 中的两个数字对数字进行范围 - How to range numbers based on two number in python 如何在python中的一行数字中求和? - how can i make a sum in a line of numbers in python? 如何在python中检索两个数字之间的列表元素? - How can i retrieve elements of a list between two numbers in python? 如果在python中输入数字,如何发出错误消息 - How can I make an error message if numbers are entered in python 如何在 python 中创建内联循环以对数字列表求和? - How can I make an inline for loops in python to sum a list of numbers? Python - 如何将数字除以复数,实现我自己的复数类? - Python - How can I divide a number by a complex number, implementing my own class for complex numbers? 如何使用python选择最高数字更紧凑? - How can I make selecting highest number more compact with python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM