Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if loop is not accepting &&
#1
I am converting a hex string value to hex integer and then shifting the bits after masking to pick only 2 bits out of 32 bits hex value. It works fine when apply if statement to check single expression but when i use && to check another similar expression it gives error as pasted below the console output. Cannot figure out what is going wrong as both expressions are same.

Console result is as follows:
2.7.14
Traceback (most recent call last):
File "C:/GPIO_Test.py", line 31, in <module>
if moder_reg_value==1 && pupdr_reg_value==1:
[b]invalid syntax: <string>, line 31, pos 36



Code is as follows:
            hex_str_moder= moder_value        
            hex_int_moder= int(hex_str_moder, 16)
            bin_moder= bin(hex_int_moder) # just to test
            hex_str_pupdr= pupdr_value
            hex_int_pupdr= int(hex_str_pupdr, 16) 
            bin_pupdr= bin(hex_int_pupdr) #just to test
            pin_number+=1
            if pin_number==-1:
             continue
            bin_moder_shift= hex_int_moder>>(pin_number*2)
            moder_reg_value= bin_moder_shift & mask
            bin_pupdr_shift= hex_int_pupdr>>(pin_number*2)
            pupdr_reg_value= bin_pupdr_shift & mask            
            if moder_reg_value==1 && pupdr_reg_value=1:  #moder_reg_value alone works,second expression is problem
                success+=1
            else:
                fail+=1
Reply
#2
There is no && operator in python. Use and
Reply
#3
thanks Gribouillis. You are right. It worked with your suggested and instead of &&.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Accepting inputs str vs int lbtdne 2 1,808 May-14-2020, 01:45 PM
Last Post: lbtdne
  Problem with accepting multiple string inputs Ryan_Todd 5 2,927 Jan-22-2020, 06:12 PM
Last Post: buran
  signal.itimer() not accepting keyword arguments Skaperen 2 2,236 Dec-19-2019, 12:14 AM
Last Post: Skaperen
  Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy) Drone4four 4 3,777 Aug-23-2019, 07:59 PM
Last Post: Drone4four
  Sqlalchemy accepting ISO 8601 KirkmanJ 0 3,572 Jul-27-2018, 01:52 PM
Last Post: KirkmanJ
  MySQL not accepting utf8mb4. Warning 3719 jonesin1974 0 4,764 Jun-21-2018, 03:09 AM
Last Post: jonesin1974

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020