Python Forum

Full Version: Lists first item is a number however i cant compare it with an int getting syntax err
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

when i try to compare list first element i am getting a syntax error. "if satırsayısı2=isimsatırlistesi[0]" this list is made of " isimsatırlistesi.append(int(satırsayısı))" so all the elements of the list are int not sure how to avoid this. Any suggestions ?


fhand=open("arb1.txt")

satırsayısı=0
isimsatırlistesi=list()
for line in fhand:
    satırsayısı=satırsayısı+1
    if line.startswith("Adres"):
        isimsatırlistesi.append(int(satırsayısı))

adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)
Use ==
if satırsayısı2==isimsatırlistesi[0]: 
Still getting the error thanks for the comment tough.
I am able to run your code without error

This code wont print anything due to satırsayısı2=satırsayısı+1
 adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)
Thanks alot looks like i forgot to use ":" at the end of if. It works thanks a bunch :).
if satırsayısı2==isimsatırlistesi[0]:

(Apr-22-2020, 09:58 AM)anbu23 Wrote: [ -> ]I am able to run your code without error

This code wont print anything due to satırsayısı2=satırsayısı+1
 adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)

Thanks for the heads up :)

now it is " satırsayısı2=satırsayısı2+1"