Can someone tell me what is the difference between while(1) and while (true) in python?

Re: While loop 80 80

Latter causes uninitialized variable error if true variable is not defined. Python is case sensitive.

Re: While loop 80 80

Please use True (it is capitalized) ...

# initialize count
count = 0
# you could use 1 instead of True, but True is clearer
while True:
    print(count)
    count += 1
    # exit condition needed to stop endless loop
    if count > 8:
        break

'''result ...
0
1
2
3
4
5
6
7
8
'''
Re: While loop 80 80

ok can you tell me what does this mean :
string = ''.join(c for c in string if c.isalpha()) ?

Re: While loop 80 80

Filter only letters from string.

Re: While loop 80 80

The generator expression says, return a list of characters for every alphabetical character in string. The .join() method (applied to an empty string, and taking the generated list as it's argument) then fuses the list elements into a new string, with no separator character between them. The practical upshot of it is to filter out any character in string that isn't a letter.

Re: While loop 80 80

what does this mean ord(a) - 97?

Re: While loop 80 80
>>> chr(97)
'a'

So look like you are desiphering code dealing with number of letter in alphabet, probably Caesar "crypto" Actually your references to code look similar to my code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.