How to find out if a Python object is a string?

前端 未结 14 1965
天涯浪人
天涯浪人 2020-11-30 17:47

How can I check if a Python object is a string (either regular or Unicode)?

14条回答
  •  既然无缘
    2020-11-30 18:19

    if type(varA) == str or type(varB) == str:
        print 'string involved'
    

    from EDX - online course MITx: 6.00.1x Introduction to Computer Science and Programming Using Python

提交回复
热议问题