Special Uses and trinocular computing else

1, eval () to obtain the original data type 
Example 1:
str = "10"
         a = eval(str)
         print(a,type(a))

 


The results obtained are a 10 integer, not a string 10
Example 2:
str1 = "1 + 3"
         a = eval(str("str1"))
         print(a,type(a))

 


a is a value obtained 3 + 1, 3 + 1 instead of the string

2, three head operation
example: a function of 1 if the function 2 conditions else
IF conditions to perform the functions 1, 2 or execute a function
for example:
    num1 = 2
        num2 = 4
        result = num1 if num1 > num2 num2
        print(result)      
View Code

 



3, else special usage
=, my_str ' ABCD ' 
        for i in , my_str:
             IF i == ' c ' :
                 Print ( ' finds the specified character ' )
                 BREAK   (not the normal end)
         else :         # Only above the normal execution of the for loop, you can perform the following else statements 
        Print ( ' did not find the specified character ' )

 

Guess you like

Origin www.cnblogs.com/wjun0/p/11515348.html