Introduction to Basics of python language

BagavathiShivakumar1 14 views 10 slides Oct 14, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

Basics of python


Slide Content

Learning Python from Basics

Language, Interpreter and IDE The word “Python” to refer to the language, and the word “interpreter” to refer to the technology that runs your Python code. “IDLE” refers to the IDE, which takes your Python code and runs it through the interpreter. It’s the interpreter that does all the actual work here.

Standard library The first line of code imports some preexisting functionality from Python’s standard library, which is a large stock of software modules providing lots of prebuilt (and high-quality) reusable code.

Standard libraries >>import sys >> sys.platform 'win32’ >>print( sys.version ) 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] To determine the identity of your underlying operating system To determine which version of Python is running

>>import os >> os.getcwd () 'C:\\Users\\Bagavathi\\ AppData \\Local\\Programs\\Python\\Python311’ >> os.getenv ('HOME') 'C:\\Users\\Bagavathi' to work out the name of the folder your code is operating within to get the environment HOME

os.environ environ({'ALLUSERSPROFILE': 'C:\\ ProgramData ', 'APPDATA': 'C:\\Users\\Bagavathi\\ AppData \\Roaming', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'BAGAVATHI-SHIVA', 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe', 'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\ DriverData ', 'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer', 'FPS_BROWSER_USER_PROFILE_STRING': 'Default', 'HOME': 'C:\\Users\\Bagavathi', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Users\\Bagavathi', 'LOCALAPPDATA': 'C:\\Users\\Bagavathi\\ AppData \\Local', 'LOGONSERVER': '\\\\BAGAVATHI-SHIVA', 'NUMBER_OF_PROCESSORS': '4', 'ONEDRIVE': 'C:\\Users\\Bagavathi\\OneDrive - Amrita Vishwa Vidyapeetham', 'ONEDRIVECOMMERCIAL': 'C:\\Users\\Bagavathi\\OneDrive - Amrita Vishwa Vidyapeetham', 'ONEDRIVECONSUMER': 'C:\\Users\\Bagavathi\\OneDrive', 'ONLINESERVICES': 'Online Services', 'OS': ' Windows_NT ', 'PATH': 'C:\\Program Files\\Common Files\\Oracle\\Java\\ javapath;C :\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\ Wbem;C :\\WINDOWS\\System32\\ WindowsPowerShell \\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\MATLAB\\R2022a\\runtime\\win64;C:\\Program Files\\MATLAB\\R2022a\\ bin;C :\\Program Files (x86)\\dotnet\\;C:\\Program Files\\Git\\ cmd;C :\\Users\\Bagavathi\\ AppData \\Local\\Microsoft\\ WindowsApps;C :\\modeltech64_10.1c\\win64;C:\\Users\\Bagavathi\\ AppData \\Local\\Programs\\ MiKTeX \\ miktex \\bin\\x64\\;C:\\Program Files\\JetBrains\\PyCharm 2022.2.3\\bin;;;C:\\Program Files\\JetBrains\\PyCharm Community Edition 2022.3\\bin;', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'PLATFORMCODE': 'KV', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'AMD64 Family 23 Model 24 Stepping 1, AuthenticAMD ', 'PROCESSOR_LEVEL': '23', 'PROCESSOR_REVISION': '1801', 'PROGRAMDATA': 'C:\\ ProgramData ', 'PROGRAMFILES': 'C:\\Program Files', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'PROGRAMW6432': 'C:\\Program Files', 'PSMODULEPATH': 'C:\\Program Files\\ WindowsPowerShell \\ Modules;C :\\WINDOWS\\system32\\ WindowsPowerShell \\v1.0\\Modules', 'PT8HOME': 'C:\\Program Files\\Cisco Packet Tracer 8.1.1', 'PUBLIC': 'C:\\Users\\Public', 'PYCHARM': 'C:\\Program Files\\JetBrains\\PyCharm 2022.2.3\\bin;', 'PYCHARM COMMUNITY EDITION': 'C:\\Program Files\\JetBrains\\PyCharm Community Edition 2022.3\\bin;', 'PYTHONPATH': 'F:\\Tools\\VSCode-win32-x64-1.70.2\\resources\\app\\extensions\\python', 'REGIONCODE': 'APJ', 'SESSIONNAME': 'Console', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\WINDOWS', 'TEMP': 'C:\\Users\\BAGAVA~1\\ AppData \\Local\\Temp', 'TMP': 'C:\\Users\\BAGAVA~1\\ AppData \\Local\\Temp', 'USERDOMAIN': 'BAGAVATHI-SHIVA', 'USERDOMAIN_ROAMINGPROFILE': 'BAGAVATHI-SHIVA', 'USERNAME': 'Bagavathi', 'USERPROFILE': 'C:\\Users\\Bagavathi', 'WINDIR': 'C:\\WINDOWS'})

>>import datetime >> datetime.date.today ().day 31 >> datetime.date.today ().month 1 >> datetime.date.today ().year 2023 >> datetime.date.isoformat ( datetime.date.today ()) '2023-01-31' To get today’s date, To pass in today’s date to display a much more userfriendly version of today’s date

>>import time >> time.strftime ("%H:%M") '13:31’ >> time.strftime ("%A %p") 'Tuesday PM' To specify how you want the time displayed To specify the day and the time currently as PM or AM

>>import html >> html.escape ("This HTML fragment contains a <script>script</script> tag.") 'This HTML fragment contains a & lt;script&gt;script&lt ;/ script&gt ; tag.' To convert to HTML

Data structures One of the data structures is the list, which can be thought of as a very powerful array. Like arrays in many other languages, lists in Python are enclosed within square brackets ([]). Interpreter won’t decide a single statement has come to an end until it finds the closing bracket (]) that matches the opening one ([). The end of the line marks the end of a statement in Python.
Tags