Now that you have a basic idea of what Python is, let's create a script. Instead of the famous Hello World!
introduction, we are going to use a cult film example. The scripts will define a function, which will print a famous quote from the 1983 cult classic WarGames. There are two ways of doing this, as mentioned previously; the first is through the interactive interpreter, and the second is through a script. Open an interactive interpreter and execute the following line:
print("Shall we play a game?\n")
The preceding print statement will show that the code execution worked. To exit the interactive interpreter, either type exit()
or use Ctrl + Z in Windows or Ctrl + D in Linux. Now, create a script in your preferred editing tool, such as vi, vim, emacs, or gedit. Then save the file in /root/Desktop
as wargames_print.py
:
#!/usr/bin/env python print("Shall we play a game?\n")
After saving the file, run it with the following command:
python /root/Desktop/wargames_print...