{"id":3127,"date":"2021-04-20T14:17:23","date_gmt":"2021-04-20T08:47:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=3127"},"modified":"2021-11-22T18:39:23","modified_gmt":"2021-11-22T13:09:23","slug":"python-programming-basics-of-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-programming-basics-of-python\/","title":{"rendered":"Python Programming \u2013 Basics of Python"},"content":{"rendered":"

In this Page, We are Providing Python Programming \u2013 Basics of Python. Students can visit for more Detail and Explanation of Python Handwritten Notes<\/a>\u00a0Pdf.<\/p>\n

Python Programming \u2013 Basics of Python<\/h2>\n

Token<\/strong><\/p>\n

A token is a string of one or more characters that is significant as a group. Consider an expression:<\/p>\n

sum=6+2<\/pre>\n

The tokens in the above expression are given in table 2-1:<\/p>\n\n\n\n\n\n\n\n\n
\n

Token<\/p>\n<\/td>\n

\n

Token type<\/p>\n<\/td>\n<\/tr>\n

\n

Sum<\/p>\n<\/td>\n

Identifier<\/td>\n<\/tr>\n
\n

=<\/p>\n<\/td>\n

Assignment operator<\/td>\n<\/tr>\n
\n

6<\/p>\n<\/td>\n

Integer literal<\/td>\n<\/tr>\n
\n

+<\/p>\n<\/td>\n

Addition operator<\/td>\n<\/tr>\n
\n

2<\/p>\n<\/td>\n

Integer literal<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

The process of converting a sequence of characters into a sequence of tokens is called “lexical analysis”. A program or function that performs lexical analysis is called a lexical analyzer, lexer, or tokenizer. A lexer is generally combined with a parser (beyond the scope of this book), which together analyze the syntax of computer language. Python supports the following categories of tokens: NEWLINE, INDENT, DEDENT, identifiers, keywords, literals, operators, and delimiters.<\/p>\n

Keywords<\/strong><\/p>\n

The following identifiers (as shown as output in the following code) are used as reserved words (or “keywords”) of the language, and cannot be used as ordinary identifiers.<\/p>\n

>>> import keyword
\n>>> for kwd in keyword.kwlist:
\n. . .\u00a0 \u00a0 print kwd
\n. . .
\nand
\nas
\nassert
\nbreak
\nclass
\ncontinue
\ndef
\ndel
\nelif
\nelse
\nexcept
\nexec
\nfinally
\nfor
\nfrom
\nglobal
\nif
\nimport
\nin
\nis
\nlambda
\nnot
\nor
\npass
\nprint
\nraise
\nreturn
\ntry
\nwhile
\nwith
\nyield<\/p>\n

One can also check if an identifier is a keyword or not using its keyword ( ) function.<\/p>\n

>>> import keyword\r\n>>> keyword . iskeyword ( ' hi ' )\r\nFalse\r\n>>> keyword . iskeyword ( ' print ' )\r\nTrue<\/pre>\n

Delimiters<\/strong><\/p>\n

The delimiter is a character that separates and organizes items of data. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values. Table 2-11 provides a list of tokens that serves as delimiters in Python.<\/p>\n\n\n\n\n\n
\n

Delimiters<\/p>\n<\/td>\n<\/tr>\n

(<\/td>\n)<\/td>\n[<\/td>\n]<\/td>\n@<\/td>\n{<\/td>\n}<\/td>\n,<\/td>\n:<\/td>\n.<\/td>\n‘<\/td>\n;<\/td>\n=<\/td>\n<\/tr>\n
+=<\/td>\n-=<\/td>\n*=<\/td>\n\/=<\/td>\n\/\/=<\/td>\n%=<\/td>\n&=<\/td>\nl=<\/td>\n\u2227=<\/td>\n>>=<\/td>\n<<=<\/td>\n**=<\/td>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

The following example shows how the use of delimiters can affect the result.<\/p>\n

 <\/p>\n

>>> 5+6\/2\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0# no delimiter used\r\n8 . 0\r\n>>> (5+6)\/2\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # delimiter used\r\n5 . 5<\/pre>\n

Following are few points that a Python programmer should be aware of:<\/p>\n