• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Python String and numbers

November 18, 2014 by Dhaval Dave

When working with data, we need ways to store it in variables so we can manipulate it.

three of the most common data types used in programming: numbers, strings and booleans. We assigned those data types to variables one-by-one, like so:

With working code below find examples and learn Python easily..

x = 3          # numbers
a = “gorillas” # strings
t = True       # booleans

PS :  To show OutPut we have used  >>  sign

Numbers

width = 20
height = 5 * 9
print width*height;
print(width*height);
>> 900
>> 900

Strings

But what if we need something more complicated, like a shopping list? Assigning a variable for every item in the list would makes things very complicated:

They can be enclosed in single quotes (‘…’) or double quotes (“…”) with the same result

item_1 = “milk”
item_2 = “cheese”
item_3 = “bread”

print ‘doesn’t’  # use ‘ to escape the single quote…
print “doesn’t”  # …or use double quotes instead

>> doesn’t


s = ‘First line.nSecond line.’
# n means newline
print s
>> First line.

Second line.

If you don’t want characters prefaced by to be interpreted as special characters, you can use raw strings by adding an r before the first quote:

print r’C:somename’  # note the r before the quote
C:somename

Strings can be concatenated (glued together) with the + operator, and repeated with *:

print 3 * ‘un’ + ‘ium’
>> unununium

If you want to concatenate variables or a variable and a literal, use +:

prefix = ‘Dhaval’
prefix = prefix + ‘Devil’
print prefix
>> DhavalDevil

See Working code at http://ideone.com/cF38M7

Similar Articles

Filed Under: Interview Questions Tagged With: Array, string

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Adobe Interview Questions 8 month Exp

K’th Largest Element in BST when modification to BST is not allowed

Maximum of all subarrays of size k

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

Maximum difference between two elements s.t larger element appears after the smaller number

Calculate price of parking from parking start end time prices

Find min element in Sorted Rotated Array (With Duplicates)

Hackerearth : Counting Subarrays

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

Convert number to words java

Introduction To Number Theory ( Part 1 )

Rectangular chocolate bar Create at least one piece which consists of exactly nTiles tiles

Amazon Interview Experience – SDE Chennai

Count Possible Decodings of a given Digit Sequence

The Magic HackerEarth Nirvana solutions Hiring Challenge

write a c program that given a set a of n numbers and another number x determines whether or not there exist two elements in s whose sum is exactly x

Facebook Interview Question : Interleave List

Stickler thief

VMWare SDEII Interview

Find position of the only set bit

Code Chef PRGIFT Solution

Maximum size of square sub matrix with all 1’s in a binary matrix

Check Binary Tree is Binary Search Tree or not

Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

Find Pythagorean Triplets in an array in O(N)

Binary Tree Isomorphic to each other

flattens 2 D linked list to a single sorted link list

Stock Buy Sell to Maximize Profit

Word Break Problem

FizzBuzz Solution C C++

Copyright © 2025 · Genesis Framework · WordPress · Log in