InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Python

    Python strings

    • Python string quick start tutorial
    • Python string split examples
    • Python string lowercase and uppercase
    • Python string contains check
    • int to string
    • string to int

    Python List (Array)

    • list basics
    • list append, prepend
    • list remove an item
    • merge lists
    • slice of list
    • array clone
    • initialize list with same value
    • value in list check

    Python Dictionary

    • dictionary basics
    • Python iterate dictionary
    • dictionary get key with default
    • sort dictionary by values

    Python control flow

    • if-elif-else
    • for loop

    Python Regex

    • re search() vs match()
    • re.match()
    • re.search()
    • re.sub()

    Python Cookbook

    • Command line - run python webserver
    • How to find python package's file location
    • Python etl petl - read table from csv file
    • Python file read write examples

    Python built-in functions

    • filter
    • filter vs ifilter
    • itertools ifilter
    • itertools imap
    • len
    • map
    • print
    • range
    • rstrip
    • type
    • xrange
     
    • Home
    • > Tutorials
    • > Python

    Python string quick start tutorial

    By admin on Jan 28, 2016

    Python built-in data type string is very frequently used in any python program. Here are some examples of using strings to get started with.

    Print a string

    s = "Hello"
    print s ## with automatic newline after string
    print "something else"
    Hello
    something else
    
    Env: Python 2.7.18

    Convert int to string

    str() convertor can be used to convert int to string or any other type to string.

    x = 10
    print str(x)
    a = [1,2]
    print str(a)
    d = {"k1":"v1", "k2":"v2"}
    print str(d)
    10
    [1, 2]
    {'k2': 'v2', 'k1': 'v1'}
    
    Env: Python 2.7.18

    Print using formatting operator %

    Strings can be printed (or assigned) using formatting operator %. It is very convenient way to print multiple values.

    s = "Hello"
    x = 10
    s1 = "%s %s" % (s, x)
    print "%s %s" % (s, x)
    print s1
    Hello 10
    Hello 10
    
    Env: Python 2.7.18

    Concatenate two strings using +

    Strings can be concatenated using + operator.

    s1 = "Hello"
    s2 = "World"
    s3 = "."
    s = s1 + s2 + s3
    print s
    HelloWorld.
    
    Env: Python 2.7.18

    Suggested posts:

    1. Python for loop examples
    2. Python string lowercase and uppercase
    3. Python int to string
    4. Python dictionary basics
    5. Python file read write examples
    6. How to use exerciser monkey tool for android stress testing
    7. HTML5 template tag hello world tutorial
    8. How to use phantomjs to create site/url snapshot thumbnail
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged Python, Python cookbook, Tutorials
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress