1 A first script
1) script1.py
1 # A first Python script 2 import sys # Load a library module 3 print(sys.platform) 4 print(2 ** 10) # Raise 2 to a power 5 x = ‘Spam!‘ 6 print(x * 8) # String repetition
this file:
- Imports a Python module (libraries of additional tools), to fetch the name of the platform
- Runs three print function calls, to display the script’s results
- Uses a variable named x, created when it’s assigned, to hold onto a string object
- Applies various object operations that we’ll begin studying in the next chapter
2) Run file
Once save this text file, run it by listing its full filename as the first argument to a python command, typed at the system shell prompt:
% python script1.py
The output result in my computer is
linux2 1024 Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
时间: 2024-10-18 01:34:36