mirror of
https://github.com/rasbt/python_reference.git
synced 2025-03-13 17:19:52 +00:00
python version info
This commit is contained in:
parent
a2f6f2c4b3
commit
447c756952
24
python2_vs_3_version_info.py
Normal file
24
python2_vs_3_version_info.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Sebastian Raschka 04/10/2014
|
||||
|
||||
import sys
|
||||
|
||||
def give_letter(word):
|
||||
for letter in word:
|
||||
yield letter
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
print('executed in Python 3.x')
|
||||
test = give_letter('Hello')
|
||||
print(next(test))
|
||||
print('in for-loop:')
|
||||
for l in test:
|
||||
print(l)
|
||||
|
||||
# if Python 2.x
|
||||
if sys.version_info[0] == 2:
|
||||
print('executed in Python 2.x')
|
||||
test = give_letter('Hello')
|
||||
print(test.next())
|
||||
print('in for-loop:')
|
||||
for l in test:
|
||||
print(l)
|
Loading…
x
Reference in New Issue
Block a user