Variables & Data Types in Python

Variables

Defining variable is very simple in python just use variable name assignment operator and value. No need of type decleartion or any other prfix. Python detects data type by it self.

Data Types

Python supports various data types some of the important types are listed below.

  • Numbers
  • Strings
  • List
  • Tuple
  • Dictionary

Numbers

For storing numeric values, python supports four different types of numeric values.

  • int
  • long
  • float
  • complex

Strings

Sequence of chracters str value can be used in different ways here are some examples of string defining and slicing a string in parts.

Different String functions

There are different functions available to manipulate a string. Some of them are given below.

  • len() returns the length of string
  • string.endsWith(“value”) return true if string ends with value
  • string.count(“c”) count value c in a string
  • string.capitalize() capitalize first character of string
  • string.upper() upper case a string
  • string.lower() lower case a string
  • string.find(‘abc’) return index of first occurrence of abc
  • string.replace(‘abc’, ‘a’) replace all abc with a in a string

Escape Sequence of Characters

Escaper sequence of characters are just like other languages

  • \n new line
  • \t tab etc.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s