Basic fundamentals of Python 1 - Ryzen Hunt

Identifiers, keywords, and variables
Parts of Python
In this post, we discuss the basic fundamentals of Python Programming language which you need to know before writing simple Python programs. Here we have described  identifiers , keywords, and variables.

Identifiers
An identifier is a name given to a variable, function, class, or module. An identifier is used to identify a variable, function, class, module, or other objects.Identifiers may be one or more characters.
In Python, Identifiers must be in the following format:
  • Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z)  or digits (0 to 9) or an underscore (_). A Python identifier must begin with an alphabet (A – Z and a – z and _).
  • An identifier cannot start with a digit but is allowed everywhere else. 1plus is invalid, but plus1 is perfectly fine.
  • Keywords cannot be used as identifiers.
  • One cannot use spaces and special symbols like !, @, #, $, %, etc. as identifiers.
  • Identifier can be of any length.
Python identifiers are case sensitive.
        Ryzen=10
         ryzen=11
Both the given examples have two different identifiers.

Keywords
Keywords are reserved words that have predefined meaning or functionality. Keywords are special vocabulary and cannot be used by programmers as identifiers for variables, functions, constants, or with any identifier name. Attempting to use a keyword as an identifier name will cause an error. There are 33 reserved words available in Python.
and      as      not     
assert      finally      or     
break      for      pass     
class      from      nonlocal     
continue      global      raise     
def      if      return     
del      import      try     
elif      in      while     
else      is      with     
except      lambda      yield     
False      True      None     

Variables
Variable is a named placeholder to hold any type of data which the program can use to assign and modify during the course of execution. In Python, there is no need to declare a variable explicitly by specifying whether the variable is an integer or a float or any other type.
Rules for variables are just the same as identifiers' rules were.
Also, follow these guidelines while naming a variable, as having a consistent naming convention helps in avoiding confusion and can reduce programming errors.
  • Python variables use lowercase letters with words separated by underscores as necessary to improve readability, like this whats_up, how_are_you. Although this is not strictly enforced, it is considered a best practice to adhere to this convention.
  • Avoid naming a variable where the first character is an underscore. While this is legal in Python, it can limit the interoperability of your code with applications built by using other programming languages.
  • Ensure variable names are descriptive and clear enough. This allows other programmers to have an idea about what the variable is representing.
Assigning values to a variable
The general syntax for assigning values to variables is as follows:
variable_name = expression
The equal sign (=) also known as simple assignment operator is used to assign values to variables. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the expression which can be a value or any code snippet that results in a value. For example,
1. >>> name = "Ryzen Hunt"
2. >>> roll no = 1906436
In ➀ string type value is assigned to a variable name, in ➁ integer type value has been assigned to variable roll no.


I hope you learned something new today. Don't forget to share and comment. And also give you valuable feedback and suggestions. Thank you.
For visit our full course of Python Programming Language click here.

Suggested Book: Hey friends, Here I got a book for you.   If you're new to Computer Programming That's gonna help you to understand and learn Python. Click here or on the image to buy now at a special price.

You may like these posts

1 comment

  1. Divya Sharma
    👍👍
  1. To insert a code use <i rel="pre">code_here</i>
  2. To insert a quote use <b rel="quote">your_qoute</b>
  3. To insert a picture use <i rel="image">url_image_here</i>